PDA

View Full Version : How to preserve selection in QTreeView



daren
16th December 2009, 23:38
Hi All,
I'm using QTreeView. I need to preserve currently selected item while some items are added or removed to/from the tree (model). Also: can I force QTreeView to never lose selection event if the focus changes to other windows?
Thanks

daren
17th December 2009, 03:14
Just found the answer..

QItemSelectionModel* selModel = selectionModel();
//save current selection
QModelIndex selected = selModel->currentIndex();

//my code that adds an item to the tree
// _model->addValue(sysPlugin, newValue);

expandAll();

//restore original selection
selModel->setCurrentIndex(selected, QItemSelectionModel::SelectCurrent);