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.

Was it helpful?

Solution

Use setSelectionMode:

treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);

And on the items you can use setSelected:

treeWidgetItem->setSelected(true);

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top