Python Forum
[PyQt] How to generically set the Header Item Data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] How to generically set the Header Item Data
#1
I am basically a newbie to PyQt5 but a long time experienced software engineer I have in the last couple of weeks been able to figure out quite a few things about PyQt5 but this one troubles me since I will eventually have numerous columns and I am having to set this information individually for each column using a separate "container" which seems counter-intuitive. This is what I have thus far -- what I am trying to figure out is how to have a single HdrItem and apply it to each of the HeaderLabels -- this gets added into a CenterPane = QSplitter(Qt.Horizontal, self) once its created and that works fine but having to do this for each and every column header seems rather cumbersome which is why it seems counter-intuitive to how PyQt5 works. Note if I do not do it this way it complains about adding duplicates and only the first column header gets the formatting

class ItemDsplyr(QTreeView):
    def __init__(self, parent):
        QTreeView.__init__(self, parent)

        HdrItem0 = QStandardItem()
        HdrItem1 = QStandardItem()
        HdrItem2 = QStandardItem()

        font = QFont()
        font.setBold(True)
        font.setPointSize(10)
        HdrItem0.setFont(font)
        HdrItem1.setFont(font)
        HdrItem2.setFont(font)

        brush = QBrush()
        brush.setColor(Qt.blue)
        brush.setStyle(Qt.SolidPattern)
        HdrItem0.setBackground(brush)

        HdrItem0.setForeground(brush)
        HdrItem1.setForeground(brush)
        HdrItem2.setForeground(brush)

        self.model = QStandardItemModel(0, 3)
        self.model.setHorizontalHeaderItem(0, HdrItem0)
        self.model.setHorizontalHeaderItem(1, HdrItem1)
        self.model.setHorizontalHeaderItem(2, HdrItem2)
        self.model.setHorizontalHeaderLabels(['Column1', 'Column2', 'Column3'])

        self.setModel(self.model)
        self.clicked.connect(self.itemSingleClicked)
Reply


Messages In This Thread
How to generically set the Header Item Data - by Denni - May-28-2019, 12:21 PM

Forum Jump:

User Panel Messages

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