简体   繁体   English

是否可以在QTreeWidget中设置多个项目?

[英]Is it possible to set multiple items selected in QTreeWidget?

setCurrentItem only sets one item selected. setCurrentItem仅设置一个选定的项目。 I don't see any method to set more than 1 item selected programmatically, but maybe I'm overlooking something? 我没有看到任何方法设置多个以编程方式选择的项目,但也许我忽略了什么?

Of course, my tree widget is configured to enable multiple selection. 当然,我的树窗口小部件配置为启用多个选择。

Note that I'm using QTreeWidget , not QTreeView . 请注意,我使用的是QTreeWidget ,而不是QTreeView

Use setSelectionMode : 使用setSelectionMode

treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);

And on the items you can use setSelected : 在项目上你可以使用setSelected

treeWidgetItem->setSelected(true);

Yes, you use the selection model: 是的,您使用选择模型:

QModelIndex index = ...; // index you want to select.
QItemSelectionModel* sel_model = tree_view->selectionModel();
sel_model->select(index, QItemSelectionModel::Select);

There are other ways of manipulating the selection mode - see the Qt Assistant for more details. 还有其他操作选择模式的方法 - 有关详细信息,请参阅Qt助手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM