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