Vertical scroll bar of Qtreeview is not proportional to the size of the content

32 views Asked by At

When you tested Qtreeview in the application below, the vertical scrollbar normally works proportional to the content.

class MyTreeView(QtWidgets.QWidget):
      def __init__(self):
          super().__init__()
        model = QtGui.QStandardItemModel(self)
        # Add some example items to the model
        numofItems = 30
        for x in range(numofItems):
            item = QtGui.QStandardItem('Test {}'.format(x+1))
            item.setCheckable(True)
            item.setCheckState(QtCore.Qt.Checked)
            model.appendRow(item)
        # Create the QTreeView
        treeView = QtWidgets.QTreeView(self)
        treeView.setModel(model)
        
        # QTreeView vertical scrollbar configuration
        v_scrollbar = treeView.verticalScrollBar()
        v_scrollbar.setMinimumWidth(15)  
        v_scrollbar.setStyleSheet("QScrollBar:vertical { width: 15px; }")
        # Main layout
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(treeView)
        self.setLayout(lay)```
  

When I use the same Qtreeview in an application that uses a QMainwindow, within a Qdock the vertical scrollbar becomes small.
0

There are 0 answers