Multiple Columns in PyQt4 (potentially using QTreeWidget)

前端 未结 1 1620
不知归路
不知归路 2021-02-10 16:14

I\'m trying to get QTreeWidget working exactly similar to this one. In python! I don\'t care about multiple tabs but about multiple columns.

相关标签:
1条回答
  • 2021-02-10 17:13

    There's a few things you'll want to fix there.

    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_())
    

    I didn't finish the example, but that should get you reasonably close.

    Note that instead of barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"]), there's nothing wrong with

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

    if you need to calculate something before displaying the text.

    0 讨论(0)
提交回复
热议问题