I have a model JSONand I fill it out QTreeView:
JSON
QTreeView
*-group1 | | | *-item1 value1 | | | *-item2 value2 | *-group2 | *-item4 value3
Now I want to turn off selection for groupsso that the user can select only rows with items. And I want to achieve it without modifying the model.
groups
items
Use a proxy model such as QIdentityProxyModel and override QAbstractItemModel :: flags () by removing the Qt :: ItemIsSelectable flag for group members:
Qt::ItemFlags DisableGroupProxyModel::flags(const QModelIndex& index) const { const auto flags = QIdentityProxyModel::flags(index); if (index is group) { return flags & ~Qt::ItemIsSelectable; } return flags; }
() - - :
DisableGroupProxyModel* proxy = new DisableGroupProxyModel(this); proxy->setSourceModel(originalModel); treeView->setModel(proxy);
QItemSelectionModel.
QItemSelectionModel
treeView->selectionModel();
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
, , previous .
previous
Source: https://habr.com/ru/post/1626195/More articles:Ajax request rejected due to Origin 'null', origin IS the same and NOT on a local or local file - javascriptHow to convert XMLTYPE to VARCHAR in ORACLE? - oracleMy code crashes when calling solve_chol () using the lapack library - cExceptionMapper in Jersey throws mapMappableContainerException - javahow to combine two different JSON into one JSON in C # - jsonR Brilliant execution order - rProduct Database - MySQL query with multiple JOINs - sqlTransition from a common element and Fresco do not work properly - androidHTML5 Video Shows a black screen when loading - javascriptWhat is the difference between types of data sources combined and uncooled? - datasourceAll Articles