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

QTreeView does not update the viewport after setting the selectionModel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.6.1
    • 5.5.1, 5.6.0
    • Widgets: Itemviews
    • None
    • fce83bd9f84883f93829e6ca9eacf098b018a02d

      #include <QApplication>
      #include <QTreeView>
      #include <QItemSelectionModel>
      #include <QStringListModel>
      #include <QTimer>
      #include <QDebug>
      
      int main(int argc, char** argv)
      {
          QApplication app(argc, argv);
      
          QStringListModel model{{"Monday", "Tuesday", "Wednesday", "Thursday"}};
      
          QTreeView view;
          view.setModel(&model);
          view.show();
      
          QTimer::singleShot(1000, &app, [&view]{
              auto selm = new QItemSelectionModel(view.model(), &view);
              auto idx = view.model()->index(1, 0);
              selm->select(idx, QItemSelectionModel::Select);
              qDebug() << "Made selection" << idx;
              view.setSelectionModel(selm);
              // view.viewport()->update();
          });
      
          return app.exec();
      }
      

      When running the above, the widget does not immediately show the selection from the selm. Causing a repaint of the viewport, either by resizing the window for example, or explicitly in code causes the selection to be painted.

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

            mmutz Marc Mutz
            ske Steve
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes