Results 1 to 7 of 7

Thread: Display System Drives in Specific Order in QTreeView

  1. #1
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Display System Drives in Specific Order in QTreeView

    I have a treeview where I am displaying all system drives using QFileSystemModel. I am looking for much better approach where a tree view can display Local Drives in one section, Removable Drive in another and so on.

    Here is the code:
    Qt Code:
    1. pSystemPrimaryModel = new QFileSystemModel(this);
    2. /* Sets the directory that is being watched by the model to currentPath by installing
    3.   a file system watcher on it. */
    4. pSystemPrimaryModel->setRootPath(QDir::currentPath());
    5. pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );
    6. // Sets the model for the view to present.
    7. ui->PrimTreeView->setModel(pSystemPrimaryModel);
    8. // Regard less how many columns you can do this using for:
    9. for(int nCount = nColCount; nCount < pSystemPrimaryModel->columnCount(); nCount++)
    10. ui->PrimTreeView->hideColumn(nCount);
    To copy to clipboard, switch view to plain text mode 
    It gives me the following:
    Image.JPG
    I want to display it like the second picture shown above. How can that be achieved?

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


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display System Drives in Specific Order in QTreeView

    Use a proxy model for sorting.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:


  5. #3
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display System Drives in Specific Order in QTreeView

    Quote Originally Posted by wysota View Post
    Use a proxy model for sorting.
    How do we do that? It will be helpful if you can guide me

  6. The following user says thank you to owais_blore for this useful post:


  7. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display System Drives in Specific Order in QTreeView

    Quote Originally Posted by owais_blore View Post
    How do we do that? It will be helpful if you can guide me
    QSortFilterProxyModel
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:


  9. #5
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display System Drives in Specific Order in QTreeView

    Basically using this, i tried to play around and did something like this:
    Qt Code:
    1. proxyModel->setSourceModel(pSystemPrimaryModel);
    2.  
    3. // Set the QStandardItemModel model of QTreeView to display audio and video files with details
    4. ui->PrimTreeView->setModel(proxyModel);
    To copy to clipboard, switch view to plain text mode 

    it didnt work..... Looks like I have to use some functions

  10. The following user says thank you to owais_blore for this useful post:


  11. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display System Drives in Specific Order in QTreeView

    Since you want to change the order of the drives only, obviously just using a proxy that sorts *everything* will not work. You need to subclass it and reimplement the comparision method taking into consideration *what* you are sorting. And I have no idea why you used QStandardItemModel instead of QFileSystemModel in the last snippet. Maybe that's why it "didn't work" (whatever that means)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:


  13. #7
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display System Drives in Specific Order in QTreeView

    Well That was a typo from my side. I have used QFileSystemModel only. Looks like I have to re-implement the comparison method.

    Quote Originally Posted by wysota View Post
    Since you want to change the order of the drives only, obviously just using a proxy that sorts *everything* will not work. You need to subclass it and reimplement the comparision method taking into consideration *what* you are sorting. And I have no idea why you used QStandardItemModel instead of QFileSystemModel in the last snippet. Maybe that's why it "didn't work" (whatever that means)

  14. The following user says thank you to owais_blore for this useful post:


Similar Threads

  1. Replies: 8
    Last Post: 8th May 2012, 00:51
  2. Changing QTableView column display order
    By scarleton in forum Qt Programming
    Replies: 3
    Last Post: 18th October 2010, 01:04
  3. display order of subwindows in mdi area
    By eric_vi in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2010, 17:05
  4. QTreeView: get current sort column and order
    By supergillis in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2008, 18:25
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 01:00

Tags for this Thread

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.