Results 1 to 2 of 2

Thread: Save & Restore a selection in QTreeWidget

  1. #1
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Save & Restore a selection in QTreeWidget

    Hi.

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

    My approach is to call this function:

    Qt Code:
    1. void QUSongTree::restoreSelection(const QModelIndexList &selectedIndexes) {
    2. QItemSelection selection;
    3.  
    4. foreach(QModelIndex index, selectedIndexes)
    5. selection.append(QItemSelectionRange(index));
    6.  
    7. selectionModel()->select(selection, QItemSelectionModel::Select);
    8. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Save & Restore a selection in QTreeWidget

    Well, ... QAbstractItemModel::index() did it...

Similar Threads

  1. QTreeWidget + Transparent Selection
    By Shamwow in forum Qt Programming
    Replies: 5
    Last Post: 12th August 2008, 11:23
  2. QPainter save() and restore()
    By babu198649 in forum Newbie
    Replies: 4
    Last Post: 28th July 2008, 10:22
  3. QTreeWidget selection
    By adhit in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2008, 10:08
  4. Replies: 1
    Last Post: 8th March 2007, 11:12
  5. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 07:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.