Important: Please read the Qt Code of Conduct -

[Solved] PySide 1.1.0: Putting a checkbox in horizontalHeader of QTableWidget

  • I would like to put a checkbox in the horizontal header of my tablewidget. Since the base object type is QTableWidgetItem, I tried this:
    @item = QtGui.QTableWidgetItem()
    self.tableWidget.setHorizontalHeaderItem(1, item)

    and I also tried this:


    Neither of them put a checkbox in the horizontal header. Any suggestions on how to get a checkbox in the horizontal header?

  • AFAIK, you can only do that by creating the checkbox as a child of the QHeaderView, and then manually reposition it to keep it in the right location.

  • Thanks, that suggestion worked well. Here's a code sample in case anyone else wants to do something similar:

    @class custom_table(QtGui.QTableWidget):

        def __init__(self, parent=None):
            QtGui.QTableWidget.__init__(self, parent)
            self.chkbox1 = QtGui.QCheckBox(self.horizontalHeader())
        def resizeEvent(self, event=None):
            self.chkbox1.setGeometry(QtCore.QRect((self.columnWidth(0)/2), 2, 16, 17))@

    The "(self.columnWidth(0)/2)" keeps the checkbox in the middle of the column header.

Log in to reply