python - PyQt4 中的多列(可能使用 QTreeWidget)

标签 python pyqt4 qtreewidget

我正在尝试让 QTreeWidget 的工作方式与这个完全相似。在 python !我不关心多个选项卡,而是关心多列。

image

这就是我到目前为止所得到的。不过,我不知道如何拥有多个 header 。

self.pointListBox = QtGui.QTreeWidget()

x=QtGui.QTreeWidgetItem()
x.setText(0,str(coords[0]))
y=QtGui.QTreeWidgetItem()
y.setText(0,str(coords[1]))

Qname=QtGui.QTreeWidgetItem()
Qname.setText(0,new_point_name)

self.pointListBox.setHeaderItem(Qname)
parent = QtGui.QTreeWidgetItem(self.pointListBox)
parent.setText(0,new_point_name)
parent.addChild(x)
parent.addChild(y)

最佳答案

您需要在那里解决一些问题。

from PyQt4 import QtCore, QtGui
import sys

app = QtGui.QApplication(sys.argv)
QtGui.qApp = app

pointListBox = QtGui.QTreeWidget()

header=QtGui.QTreeWidgetItem(["Tree","First","secondo"])
#...
pointListBox.setHeaderItem(header)   #Another alternative is setHeaderLabels(["Tree","First",...])

root = QtGui.QTreeWidgetItem(pointListBox, ["root"])
A = QtGui.QTreeWidgetItem(root, ["A"])
barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"])
bazA = QtGui.QTreeWidgetItem(A, ["baz", "a", "b"])


pointListBox.show()
sys.exit(app.exec_())

我没有完成这个例子,但那应该让你相当接近。

请注意,不是 barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"]),而是

barA = QtGui.QTreeWidgetItem(A)
barA.setText(0,"bar")
barA.setText(1,"i")
barA.setText(2,"ii")

如果您需要在显示文本之前计算一些内容。

关于python - PyQt4 中的多列(可能使用 QTreeWidget),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11980149/

相关文章:

python - Python 上的 Tkinter 显示某些(单色)图像困惑

python - 长流程中的 PYQT 和进度条

python - 在调用函数时如何防止 GUI 卡住? (PyQT4, Python3)

c++ - 如何在鼠标单击时获取 QTreeWidget 中当前选定项的绝对路径

python - 将 pyQt UI 转换为 python

python - Boto connect_xxx 方法和连接池

python - 这应该工作 : open() in python

python - PyQt4 qTableView对齐

c++ - 将子项目插入一行 QTreeWidgetItem

python - PyQt : How to expand all children in a QTreeWidget