[PyQt] QTreeView branches and their clickable area not coinciding - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] QTreeView branches and their clickable area not coinciding (/thread-2444.html) |
QTreeView branches and their clickable area not coinciding - abstracted - Mar-17-2017 I am creating a property editor that controls various document parameters. It is done using implementations of QTreeView, QAbstractItemModel, and QStyledItemDelegate. In the name of space usage and attractiveness I have un-indented the grandchildren of the (invisible) root node. I did this by reimplementing QtyledItemDelegate.paint() and QTreeView.drawBranches() to remove 20 pixels (the default indentation) from the QRect of these items. The problem is that while I can visually un-indent these rows, the area that is clickable to expand/collapse the row does not move (see the image below). How could I fix this? I have provided code snippets below. I have an image showing what I mean here, but it appears I cannot add it due to this being my first post. Nevertheless you can see it on my post on stackoverflow -- stackoverflow.com/questions/42600271/qtreeview-branches-and-their-clickable-area-not-coinciding class PropertyTreeDelegate(QStyledItemDelegate): def __init__(self, form, *args, **kwargs): ... def paint(self, painter, option, index): ... # Unindent the row if the number of parents is greater than 1 if num_parents > 1 and column == 0: option.rect.adjust(-20, 0, 0, 0) ... class PropertyTreeView(QTreeView): def __init__(self, form, *args, **kwargs): ... def drawBranches(self, painter, rect, index): ... # If the node has more than 1 parent unindent if num_parents > 1: rect.adjust(-20, 0, -20, 0) ... |