对于这个问题,我指的是@Andy PyQt Tree Widget的答案,添加了动态删除的复选框
@Andy 展示了如何添加CheckBox
到 中QTreeWidget
,效果很好。
我想在这里问一下,如何RadioButton
添加QTreeWidget
?----而且,这对我来说更难,如何只选择一个项目,尽管它们不同groups
?
我将 @Andy 的代码重写为 PyQt5:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
def main():
app = QApplication (sys.argv)
tree = QTreeWidget ()
headerItem = QTreeWidgetItem()
item = QTreeWidgetItem()
for i in range(3):
parent = QTreeWidgetItem(tree)
parent.setText(0, "Parent {}".format(i))
parent.setFlags(parent.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
for x in range(5):
child = QTreeWidgetItem(parent)
child.setFlags(child.flags() | Qt.ItemIsUserCheckable)
child.setText(0, "Child {}".format(x))
child.setCheckState(0, Qt.Unchecked)
tree.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
上面代码的运行结果:
任何帮助将不胜感激!谢谢!