0

i would like to add a check box in the first column of my QtableIwdget.The end motive is to use it to select/unselect all.I have seen some solutions on the internet but of C++.I would like to do this in python(pyqt5).I have tried this:

    chkBoxItem = QTableWidgetItem()
    chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
    self.table.setHorizontalHeaderItem(0, chkBoxItem)

where table is my QTableWidgetItem.Any help?

alvy
  • 117
  • 1
  • 10
  • What you're trying is useless, as QHeaderView doesn't use the normal QStyleOption mechanism of items (nor delegates can be set as noted [in the documentation](https://doc.qt.io/qt-5/qheaderview.html#appearance)). Subclass the header and override the [`paintSection()`](https://doc.qt.io/qt-5/qheaderview.html#paintSection) function, then use `setHorizontalHeader()` as shown in the answers linked above. – musicamante Sep 28 '22 at 01:27

0 Answers0