Important: Please read the Qt Code of Conduct -

How to set the row height of QTableWidget

  • Hi,

    I am trying to set the row height of my QTableWidget but no matter what I try they are not getting smaller. Are there some hard coded values that qt is using not to respect the assigned height.

    Here is the PySide code:

    class NodeTableWidget(QtWidgets.QTableWidget):
        allFiles = []
        def __init__(self, parent=None):
            super(NodeTableWidget, self).__init__(parent)
            #delegate = AlignDelegate(self)
            self.setHorizontalHeaderLabels(("Embedded Nodes","Context"))
            self.setRowHeight(0, 10);
            hh = self.horizontalHeader()
            #hh.setSectionResizeMode(0, QtGui.QHeaderView.Stretch)
            #self.setColumnWidth(1, 0)
            vh = self.verticalHeader()
            print self.rowHeight(0)
            #vh.resizeSection(0, 5)
            #vh.resizeSection(1, 5)
            nodes = hou.node("/").allNodes()
            nodes = [n for n in nodes if not n.isNetwork() and != "localscheduler"]
            nodenames = ["{0} ({1})".format(, n.type().name()) for n in nodes]
            nodetypes = [n.type().name() for n in nodes]
            nodecontexts = [n.type().category().name().upper() for n in nodes]
            nodeicons = []
            boxIcon = findNodeByType("Sop", "box").icon()
            iconsize = hou.ui.scaledSize(16)
            icons = [n.type().icon() for n in nodes]
            for icon in icons:
                    qtIcon = hou.qt.Icon(icon, width=iconsize, height=iconsize)
                    qtIcon = hou.qt.Icon(boxIcon, width=iconsize, height=iconsize)
            #filedates = [time.ctime(os.path.getmtime(file)) for file in files]
            #self.allFiles = files
            for index, node in enumerate(nodenames):
                self.setRowHeight(index, 10)
                nodeicon = QtWidgets.QTableWidgetItem()
                nodeicon.setFlags(nodeicon.flags() & ~QtCore.Qt.ItemIsEditable)
                #self.setItem(0, 0, nodeicon)
                nodename = QtWidgets.QTableWidgetItem(node)
                nodename.setFlags(nodename.flags() & ~QtCore.Qt.ItemIsEditable)
                #nodetype = QtWidgets.QTableWidgetItem(nodetypes[index])
                #nodetype.setFlags(nodetype.flags() & ~QtCore.Qt.ItemIsEditable)
                nodecontext = QtWidgets.QTableWidgetItem(nodecontexts[index])
                nodecontext.setFlags(nodecontext.flags() & ~QtCore.Qt.ItemIsEditable)
                #self.setItem(index, 0, nodeicon)
                self.setItem(index, 0, nodename)
                #self.setItem(index, 1, nodetype)
                self.setItem(index, 1, nodecontext)

    I want half the height of these:

    Thanks in advance.

  • setMinimumSectionSize worked but it seems to clip the vertical row headers a bit? Is there a way to fix this?

  • @lachdanan
    Make the minimum size a bit bigger!?

  • You mean for the QTableWidgetItem? Because I don't want to change its size, it's good now. But the vertical header size is clipped.

  • @lachdanan
    All I know is looking at your screenshot the height seems to be enough for the content items but not quite enough vertically for the row headers/labels. Maybe it's a font thing, I don't know.

  • @JonB Yes I reduced the size of the font just for the row headers. But to me this seems strange, like I have to tweak every little thing myself. I would have expected setting the row height would ensure everything looks correctly.

Log in to reply