Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] PySide 1.1.0: Putting a checkbox in horizontalHeader of QTableWidget
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    karnisov
    wrote on last edited by
    #1

    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()
    item.setCheckState(QtCore.Qt.Checked)
    self.tableWidget.setHorizontalHeaderItem(1, item)
    @

    and I also tried this:

    @self.tableWidget.horizontalHeaderItem(1).setCheckState(QtCore.Qt.Checked)
    @

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karnisov
        wrote on last edited by
        #3

        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):
                super().resizeEvent(event)
                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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved