I have the following situation: I need to create a custom tree control whose checkboxes are also configured. I easily made most of the settings for managing the tree using style sheets; I managed to add checkboxes to the QTreeView elements, but I had big problems setting them up - I need to display a custom image for the checked state, and another for the uncontrolled state.
The place where I concluded this can be done in my QStyledItemDelegate subclass, in the paint event (i.e. CheckBoxItemDelegate :: paint). I need to display the text, icon and checkbox for the item. But the problems are:
- I canβt get the style of the element (which I set using the stylesheet) - otherwise my text can be drawn with the wrong color,
- I do not know the errors of each sub-element (flag, icon, text).
- I do not know how to get the icon of an element (given its QModelIndex) to draw it.
PS I have subclassed QTreeView (obviously), and when I work with QFileSystemModel, I also subclassed it to add functionality to it.
Can someone help me please? Is QStyledItemDelegate :: draw a suitable place to change the visual checkbox elements for tree items? If so, can you give me a small example or something else, how can I do this?
source share