问题描述
有人知道是否有可能在QTreeWidget上选择多个项目以及如何启用多个选择吗?
Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection?
我要选择的所有项目都是顶级QTreeWidgetItems,所有子项都设置为禁用(即QTreeWidgetItem.setDisabled(True))
All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e QTreeWidgetItem.setDisabled(True) )
推荐答案
是的,您将要调用 setSelectionMode 在初始化过程中启用QAbstractItemView :: MultiSelection. QTreeView/QTreeWidget继承了QAbstractItemView,因此可用.
It is, you'll want to call setSelectionMode during init to enable QAbstractItemView::MultiSelection. QTreeView/QTreeWidget inherit QAbstractItemView, so it is available.
然后要禁用这些项目,只需挂接到QTreeWidgets.itemSelectionChanged()信号即可.
Then to disable the items, just hook on to QTreeWidgets.itemSelectionChanged() signal.
这篇关于多项选择QTreeWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!