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

QTreeView does not update the viewport after setting the selectionModel

    XMLWordPrintable

Details

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

    Description

      #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.

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes