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

Change in SizeHintRole does not trigger QTreeView re-layout when uniformRowHeights enabled

    XMLWordPrintable

Details

    • 4a4458d1cf5ec7885c6f63f739b7ee80c70ad211, 8c10e0b73c312a6c1aacce11cc8d6f57dc94a09d

    Description

      When the uniformRowHeights property is enabled for a QTreeView, changing the SizeHintRole for first item in the model does not trigger a re-layout of all the items, causing a temporary painting glitch. It's not until the user clicks somewhere in the view that a redraw is triggered. Here is a small example to demostrate the problem:

      #include <QtGui>
      #include <QtCore>
      
      class MyWidget : public QWidget
      {
      Q_OBJECT
      public:
      	MyWidget(QWidget *parent=0) {
      		model = new QStandardItemModel(10, 10, this);
      		for (int row = 0; row < 10; row++) {
      			for (int col = 0; col < 10; col++) {
      				QStandardItem *item = new QStandardItem(QString("row %0, col %1").arg(row).arg(col));
      				model->setItem(row, col, item);
      			}
      		}
      		view = new QTreeView(this);
      		view->setUniformRowHeights(true);
      		view->setModel(model);
      		button = new QPushButton("Set SizeHint", this);
      		connect(button, SIGNAL(clicked()), this, SLOT(foo()));
      	
      		layout = new QVBoxLayout(this);
      		layout->addWidget(view);
      		layout->addWidget(button);
      	}
      
      public slots:
      	void foo() {
      		qDebug("Setting size hint on row 0, col 5 to QSize(100,100)");
      		QModelIndex index = model->index(0, 5);
      		model->setData(index, QVariant(QSize(100,100)), Qt::SizeHintRole);
      	}
      
      private:
      	QTreeView *view;
      	QStandardItemModel *model;
      	QPushButton *button;
      	QVBoxLayout *layout;
      };
      
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          MyWidget w;
          w.resize(800,600);
          w.show();
          return a.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dedietri Gabriel de Dietrich (drgvond)
            jugdish Jugdish
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes