Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11151

Scene is not centered after changing size of rect

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • 4.7.1
    • 4.6.2
    • Widgets: GraphicsView
    • 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);
      }
      

      Attachments

        1. graphicsview_test.zip
          408 kB
        2. test.png
          test.png
          18 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            anno Hans Müller
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes