Results 1 to 2 of 2

Thread: How to preserve selection in QTreeView

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to preserve selection in QTreeView

    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

  2. #2
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to preserve selection in QTreeView

    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);

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. QTreeView selection strangeness
    By jkv in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2009, 06:50
  3. Custom selection actions in QTreeView
    By iraytrace in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 20:51
  4. Selection row in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2008, 22:31
  5. Qtreeview selection highlighted problem?
    By thefisher in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2006, 09: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
  •  
Qt is a trademark of The Qt Company.