Python Forum
[PyQt] QTreeView branches and their clickable area not coinciding
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QTreeView branches and their clickable area not coinciding
#1
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)
        ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QTreeView, StyleSheet resizes last column malonn 2 855 Sep-15-2023, 03:50 PM
Last Post: malonn
  [PyQt] Changing a column header in QTreeView DrakeSoft 4 3,478 Jun-25-2022, 09:11 AM
Last Post: DrakeSoft
  [Tkinter] Clickable Rectangles Tkinter Canvas MrTim 4 8,659 May-11-2021, 10:01 PM
Last Post: MrTim
  [Tkinter] Glow text of clickable object on hover with transition andy 6 5,908 May-11-2021, 07:39 AM
Last Post: andy
  Making text clickable with binding DT2000 10 5,028 Apr-02-2020, 10:11 PM
Last Post: DT2000
  [PyQt] How to reference QTreeView QHeaderView setResizeMode Denni 1 3,688 Jun-11-2019, 10:20 PM
Last Post: Alfalfa
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 4,694 Apr-15-2018, 12:41 PM
Last Post: vladlenPy
  pyqt clickable pushbutton problem pythonck 1 7,592 Dec-12-2017, 03:38 PM
Last Post: pythonck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020