From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

QListView : how to set selection after reset

  • I've created a QListView, with a QStringListModel. If I call model->setStringList(), the model & the selectionModel are being reset, thus there is no valid selection anymore. I'd like to select the first item in such case, but overwriting QListView::reset() with [1] didn't do anything. Any help?


    void PatchedListView::reset() {
      selectionModel()->setCurrenIndex(model()->index(0,0), QItemSelectionModel::SelectCurrent);
      // debugging shows the index is valid & as expected, the second time this breakpoint is hit

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What about using setCurrentIndex ?

Log in to reply