Results 1 to 3 of 3

Thread: QTreeView/QDirModel persisting current directory selection

Hybrid View

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

    Default Re: QTreeView/QDirModel persisting current directory selection

    Just to close this off I found a reasonable solution.
    Calling setCurrentIndex() expands to the selected node.
    Calling setExpanded() expands the selected node too.
    Qt Code:
    1. class DirectoryTree : public QTreeView
    2. {
    3. public:
    4. void readSettings(QSettings& oSettings)
    5. {
    6. QString sLastSelection = oSettings.value("LastSelection").toString();
    7. if (!sLastSelection.isEmpty()) {
    8. QModelIndex index = m_oModel.index(sLastSelection);
    9. setCurrentIndex(index);
    10. setExpanded(index, true);
    11. }
    12. }
    13.  
    14. void writeSettings(QSettings& oSettings) {
    15. oSettings.setValue("LastSelection", m_oModel.filePath(currentIndex()));
    16. }
    17.  
    18. protected:
    19. QDirModel& m_oModel;
    20. };
    To copy to clipboard, switch view to plain text mode 

    cheers
    Dave
    Last edited by bigduv; 4th April 2008 at 13:29.

  2. The following user says thank you to bigduv for this useful post:

    babu198649 (31st July 2008)

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. Replies: 15
    Last Post: 21st April 2007, 17:46

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.