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. How to set the row height of QTableWidget

How to set the row height of QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 5.5k Views
  • 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.
  • L Offline
    L Offline
    lachdanan
    wrote on last edited by lachdanan
    #1

    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)
            self.installEventFilter(self)
            
            #delegate = AlignDelegate(self)
            #self.setItemDelegate(delegate)
            
            self.setItemDelegate(QtWidgets.QItemDelegate())
            self.setColumnCount(2)
            #self.setMinimumHeight(2)
            #self.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
            self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows);
            self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
            self.setHorizontalHeaderLabels(("Embedded Nodes","Context"))
            self.setAlternatingRowColors(True)
            self.setShowGrid(False)
            self.setRowHeight(0, 10);
            
            hh = self.horizontalHeader()
            hh.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
            #hh.setFixedHeight(5)
            #hh.setSectionResizeMode(0, QtGui.QHeaderView.Stretch)
            #self.setColumnWidth(1, 0)
            #hh.hide()
            
            vh = self.verticalHeader()
            vh.setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
            
            print self.rowHeight(0)
            #vh.resizeSection(0, 5)
            #vh.resizeSection(1, 5)
            #vh.setDefaultSectionSize(5)
            
            nodes = hou.node("/").allNodes()
            nodes = [n for n in nodes if not n.isNetwork() and n.name() != "localscheduler"]
            
            nodenames = ["{0} ({1})".format(n.name(), 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:
                try:
                    qtIcon = hou.qt.Icon(icon, width=iconsize, height=iconsize)
                except:
                    qtIcon = hou.qt.Icon(boxIcon, width=iconsize, height=iconsize)
                    
                nodeicons.append(qtIcon)
            
            
            
            #filedates = [time.ctime(os.path.getmtime(file)) for file in files]
            
            
                    
            #self.allFiles = files
            for index, node in enumerate(nodenames):
                self.insertRow(index)
                self.setRowHeight(index, 10)
                
                nodeicon = QtWidgets.QTableWidgetItem()
                nodeicon.setFlags(nodeicon.flags() & ~QtCore.Qt.ItemIsEditable)
                #nodeicon.setTextAlignment(QtCore.Qt.AlignCenter)
                nodeicon.setIcon(nodeicons[index])
                #self.setItem(0, 0, nodeicon)
                #self.setCentralWidget(self)
            
            
    
                        
                
                nodename = QtWidgets.QTableWidgetItem(node)
                nodename.setFlags(nodename.flags() & ~QtCore.Qt.ItemIsEditable)
                #nodename.setTextAlignment(QtCore.Qt.AlignCenter)
                nodename.setIcon(nodeicons[index])
                
                #nodetype = QtWidgets.QTableWidgetItem(nodetypes[index])
                #nodetype.setFlags(nodetype.flags() & ~QtCore.Qt.ItemIsEditable)
                #nodetype.setTextAlignment(QtCore.Qt.AlignCenter)
                
                nodecontext = QtWidgets.QTableWidgetItem(nodecontexts[index])
                nodecontext.setFlags(nodecontext.flags() & ~QtCore.Qt.ItemIsEditable)
                nodecontext.setTextAlignment(QtCore.Qt.AlignCenter)
                
                #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:

    https://i.imgur.com/iawx3h4.png

    Thanks in advance.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lachdanan
      wrote on last edited by lachdanan
      #2

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

      https://i.imgur.com/CAHUC5A.png

      JonBJ 1 Reply Last reply
      0
      • L lachdanan

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

        https://i.imgur.com/CAHUC5A.png

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @lachdanan
        Make the minimum size a bit bigger!?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lachdanan
          wrote on last edited by
          #4

          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.

          JonBJ 1 Reply Last reply
          0
          • L lachdanan

            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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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.

            L 1 Reply Last reply
            0
            • JonBJ JonB

              @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.

              L Offline
              L Offline
              lachdanan
              wrote on last edited by
              #6

              @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.

              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