1

Could anyone help me understand the following behaviour? If I run this PyQt script I can generate a simple window with a QTreeView with multiple child items:

import sys
from PyQt4.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem, QVBoxLayout
from PyQt4.QtCore import QStringList

app = QApplication(sys.argv)

win = QWidget()
win.resize(320, 240)
win.setWindowTitle("Hello, Overflowers!")

treeWidget = QTreeWidget()
treeWidget.setColumnCount(1)

def addChildWidgets(parent, depth=1):
    child = QTreeWidgetItem(parent, QStringList([repr(depth)]*(depth+1)))
    if (depth<12):
        addChildWidgets(child, depth+1)
    return child

item = QTreeWidgetItem(treeWidget, QStringList(["root"]))
addChildWidgets(item)    

treeWidget.insertTopLevelItems(0, [item])

layout = QVBoxLayout()
layout.addWidget(treeWidget)

win.setLayout(layout)
win.show()

sys.exit(app.exec_())

I get the children I expect:

1 column

However, if I change the column count,

treeWidget.setColumnCount(10)

I now get my children clipped after 6 levels

enter image description here

Many thanks!

Phil

Phil Boltt
  • 786
  • 6
  • 14
  • 2
    There appears to be nothing wrong with your code here. When I run this code with 10 columns in the tree widget, I get all 12 levels in the tree - BUT the displayed width of your first column is only wide enough to display the first 4 levels of the tree, if you manually widen that column (you may even have to manually increase the size of the dialog as well) you can see all 12. – Raceyman May 26 '11 at 13:03
  • Indeed! I was getting confused by the fact that I wasn't getting an expand icon for the last child. Thanks! – Phil Boltt May 26 '11 at 21:05

0 Answers0