Details
-
Bug
-
Resolution: Invalid
-
P3: Somewhat important
-
4.6.2
-
None
Description
I think there is a bug in QGraphicsView. I crated a little sample application to show the problem.
//mainwindow.h #include <QMainWindow> #include <QGraphicsScene> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); protected: void changeEvent(QEvent *e); QGraphicsScene *scene; private: Ui::MainWindow *ui; private slots: void click123(); }; //mainwindow.cpp MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); scene = new QGraphicsScene(); scene->addRect(0, 0, 400, 50); ui->graphicsView->setScene(scene); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(click123())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void MainWindow::click123() { scene->clear(); scene->addRect(0, 0, 100, 50); }
I attached the whole project and image how it looks before and after the button was pressed.
Here I excpect that the second rectangle is centred like the first one but it isn't.
If I set a bigger at the click slot it works fine but not if I set a smaller width than before.
void MainWindow::click123() { scene->clear(); scene->addRect(0, 0, 500, 50); }