簡體   English   中英

是否可以在QTreeWidget中設置多個項目?

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

setCurrentItem僅設置一個選定的項目。 我沒有看到任何方法設置多個以編程方式選擇的項目,但也許我忽略了什么?

當然,我的樹窗口小部件配置為啟用多個選擇。

請注意,我使用的是QTreeWidget ,而不是QTreeView

使用setSelectionMode

treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);

在項目上你可以使用setSelected

treeWidgetItem->setSelected(true);

是的,您使用選擇模型:

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

還有其他操作選擇模式的方法 - 有關詳細信息,請參閱Qt助手。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM