Unsolved Gray out an item in TreeView without making it not selectable / right-clickable
-
Hi,
i have a QTreeView, that display a custom TreeModel.
Now i want to activate/deactivate item (by right-clicking them)Deactivating works by setting the falg to not be Qt::ItemIsEnabled.
However then i cannot activate it again since when the flag Qt::ItemIsEnabled is not set the rightclick does not work any more and the item is not selectable.Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?
-
@gde23
You could use a stylesheet orQStyledItemDelegate
to alter its display to some sort of "dimmed". You would need to store the desired state somewhere, such as in the item's data. -
@gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:
Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?
return a desired color for
Qt::ForegroundRole
for the corresponding index in your data() implementation. -
@raven-worx
Thanks, this works.
Except for the border of the QCheckBoxes (for the cheackable items).
They are still very bright. Do i have to set a style-sheet for those explicitly? -
@gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:
Except for the border of the QCheckBoxes (for the cheackable items).
They are still very bright. Do i have to set a style-sheet for those explicitly?you won't be able to style those explicitly, since you do not set the state to disabled.
-
@raven-worx
Just OOI, how difficult/easy would it be to stick to right-click actually disabling the item and then recognise right-click-on-disabled-item (widget event filter??), so that you can toggle back to enabled? -
@JonB said in Gray out an item in TreeView without making it not selectable / right-clickable:
Just OOI, how difficult/easy would it be to stick to right-click actually disabling the item and then recognise right-click-on-disabled-item (widget event filter??), so that you can toggle back to enabled?
yes it's possible to overrride the view's viewportEvent() and use indexAt().
But this is then view dependent, and not implemented in the model anymore. Depends if this is desired.