具有多列的 QTreeWidget 限制子项的数量
谁能帮助我理解以下行为?如果我运行这个 PyQt 脚本,我可以生成一个带有 QTreeView 的简单窗口,其中包含多个子项:
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_())
我得到了我期望的子项:
但是,如果我更改列数,
treeWidget.setColumnCount(10)
现在我的孩子会在 6 个级别后被剪掉
许多谢谢!
菲尔
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:
However, if I change the column count,
treeWidget.setColumnCount(10)
I now get my children clipped after 6 levels
Many thanks!
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论