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

Qt::ItemIsSelectable and QTreeView



  • After playing around with the following function:

    virtual Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex& index) const;
    

    as expected, not returning Qt::ItemIsSelectable prevents the item from being selected/unselected, but it also gets removed from the selectionModel().selectedIndicies() list even if it was last known to be selected. There is never a notification of a selection change for that item, so it still appears as selected.

    I would think that not returning Qt::ItemIsSelectable would only prevent an item from changing it's selection state, not completely removing all selection related functionality.

    The use case here is that I would like to have items in a tree view that are in a "locked" state where selection cannot be changed, but are still properly reported as selected by the model.

    I am currently working around this by allowing a selection change but immediately changing it right back, which seems to function without visible artifacts but does not seem ideal.


Log in to reply