Question

setCurrentItem only sets one item selected. 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.

Était-ce utile?

La solution

Use setSelectionMode:

treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);

And on the items you can use setSelected:

treeWidgetItem->setSelected(true);

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top