Pregunta

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.

¿Fue útil?

Solución

Use setSelectionMode:

treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);

And on the items you can use setSelected:

treeWidgetItem->setSelected(true);

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top