Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to check if no treeitem is selected in the tree view
summit last edited by
This is how i get the selected item in the tree view.
QModelIndex index = currentTreeView->selectionModel()->currentIndex();
How would i get to know if no item is selected in the tree view.
Kent-Dorfman last edited by
Assuming a QTreeView, I believe selectionModel() is not relevant. The inherited abstract class contains direct access to currentIndex() and the returned object contains status methods for the index.
JonB last edited by JonB
You can try his way. For my part I would first have looked at
currentTreeView->selectionModel()->selectedIndexes().count() == 0, or directly from
currentTreeView->selectedIndexes().count() == 0.
in Qt current items are not necessarily the same as selected items....
correct, and it's also explained in the docs: https://doc.qt.io/qt-5/model-view-programming.html#current-item-and-selected-items
JonB last edited by
Oh, excellenty to the reference! Current item and selected items Is that subsection new in the docs, in the past I didn't find that explanation?
Is that subsection new in the docs, in the past I didn't find that explanation?
It's already there since some years... :)