Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How setCurrentIndex to none?



  • After deletion item in my QListView i want to set current index to NONE, it's automatically change it to next, but i want no item selected.

    Tried fill it with empty index(it's all my poor imagination capable for now)

    QModelIndex *noIndx = new QModelIndex();
    ui->listV->setCurrentIndex(noIndx);
    

    it rejects to compile because "want const model index, not this scum".

    UPDATE:

    Found:

    selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
    

    But it seems working but only apart. View works like nothing selected(which already good), but visually closest item still selected.



  • @Engelard

    it rejects to compile because "want const model index, not this scum".

    void QAbstractItemView::setCurrentIndex(const QModelIndex &index) (http://doc.qt.io/qt-5/qabstractitemview.html#setCurrentIndex)

    So it takes a QModelIndex &, not a QModelIndex *:

    QModelIndex *noIndx = new QModelIndex();
    ui->listV->setCurrentIndex(*noIndx);
    

    or (simpler, no clean up):

    ui->listV->setCurrentIndex(QModelIndex());
    

Log in to reply