I have a QStandardItemModel being displayed in two QTreeViews. The first TreeView uses the standard QStyledItemDelegate without any alterations and shows the items with a checkbox, an icon and their display text. The second view is supposed to show the same tree, although a custom implementation of QStyledItemDelegate is supposed to do the following:
- Show some items' display text in italics
- Show some items' display text in red
- Remove the checkbox for every item
- Make only those items selectable that are not italics
Whether items are in italics/not clickable or not and whether they're displayed in red or not is saved in a custom DataRole and accessed using index.data(custom_role).
My problem is: I can't get text to be shown in red and I have no idea how to remove the checkbox, or how to make items selectable or not.
Here's what I have:
class PostProcessedDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self):
super().__init__()
def paint(self, painter, option, index):
custom_option = QtWidgets.QStyleOptionViewItem(option)
custom_painter = painter
if not index.data(Item.IS_PROCESSED):
custom_option.font.setItalic(True)
#ALSO MAKE ITEM NON-SELECTABLE HERE
if index.data(Item.HAS_PROCESSING_ERROR):
custom_painter.setPen(QtGui.QColor(255,0,0)) #THIS DOESNT HAVE ANY EFFECT
#REMOVE CHECKBOX BEFORE PAINTING
super().paint(custom_painter, custom_option, index)
This screenshot shows the first TreeView to the left (the one without any alterations) and the second to the right, with only some of the required changes in effect.