PDA

View Full Version : Save & Restore a selection in QTreeWidget



youkai
1st September 2008, 19:30
Hi.

I want to restore a selection in a QTreeWidget object, which I just before cleared (clearSelection()).

My approach is to call this function:


void QUSongTree::restoreSelection(const QModelIndexList &selectedIndexes) {
QItemSelection selection;

foreach(QModelIndex index, selectedIndexes)
selection.append(QItemSelectionRange(index));

selectionModel()->select(selection, QItemSelectionModel::Select);
}

I got "selectedIndexes" from a function with the same name. ;) But those indexes change between clearing and restoring the selection.

Then I did want to get the right QModelIndex after my operation on my own to restore the selection - but how to do this without a rootIndex()?

Why is QTreeWidget::rootIndex() always invalid?

I know the rows of these items which should be selected through QTreeWidget::indexOfTopLevelItem(). How to get the right model indexes to these items?

It is not a wanted solution to call QTreeWidgetItem::setSelected(bool) because that is the status quo in my project here and terribly slow due to heavy signal emitting of itemSelectionChanged()... I did disconnect my 2 functions which use that signal, but it wasn't better.

My operation got a speedup of 10-times with clearing the current selection at first. ;)

Any ideas?

youkai
1st September 2008, 19:54
Well, ... QAbstractItemModel::index() did it... :o