QTableView selects items not having flag Qt::ItemIsSelectable
-
Hello! We have a
QTableViewconnected to a custom model derived fromQStandardItemModel. This model is pretty normal: rows consisting of a fixed number of columns. However one of the columns has removed theQt::ItemFlagQt::ItemIsSelectable. But theQTableViewcontinues to select items in this column, both visually and functionally (the view's selection model emits signalQItemSelectionModel::selectionChanged()with corresponding model index). The non-selectable item is selected both with selection behaviorSelectItemsandSelectRows.Is this correct behavior of
QTableView? Why doesn't the standard widgetQTableViewrespect the item's properties in the underlying model?I just want to catch clicks on these items (this column) using
QAbstractItemView::clicked(), but I don't want to change the selection or change the focus (set new current item for the view). Is this possible? -
Hello! We have a
QTableViewconnected to a custom model derived fromQStandardItemModel. This model is pretty normal: rows consisting of a fixed number of columns. However one of the columns has removed theQt::ItemFlagQt::ItemIsSelectable. But theQTableViewcontinues to select items in this column, both visually and functionally (the view's selection model emits signalQItemSelectionModel::selectionChanged()with corresponding model index). The non-selectable item is selected both with selection behaviorSelectItemsandSelectRows.Is this correct behavior of
QTableView? Why doesn't the standard widgetQTableViewrespect the item's properties in the underlying model?I just want to catch clicks on these items (this column) using
QAbstractItemView::clicked(), but I don't want to change the selection or change the focus (set new current item for the view). Is this possible?@nullptr said in QTableView selects items not having flag Qt::ItemIsSelectable:
The non-selectable item is selected both with selection behavior SelectItems and SelectRows.
Qt::ItemIsSelectableflag only refers to (allowing/preventing) user-selectable (e.g. by clicking), not programmatic selectable. So how is the selection happening? -
Yes,
Qt::ItemIsSelectableaffects user selection (view), i.e. if I click a table cell and selection behavior isSelectRows, the view will select the row containing that cell. But then the selection will also contain the item with no flagQt::ItemIsSelectablewhich I find strange. The selection will also happen with selection behaviorSelectItems. It seems thatQTableViewignores the non-selectable property of the underlying item when it presents the data model for the user.Is this a bug or a feature?
-
Sorry, it turns out that our model was wrapped in a
QSortFilterProxyModelwhich overrided theflags()method. I didn't know this. This reimplementation ignored the actual item flag in the wrapped model. Now I can see thatQTableViewis working as it should :)QTableViewstill changes focus (changes current index) when any cell is clicked. Not sure if this can be prevented, I'll take a look.