Results 1 to 4 of 4

Thread: Sort System Drives via QSortFilterProxyModel

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

    Post Sort System Drives via QSortFilterProxyModel

    I just want to know which function of QSortFilterProxyModel class is used to sort the local and removable drives in system. Basically I am working on a app where I am using treeview and I need to sort them in a order.

    Here is the code:
    Qt Code:
    1. pSystemPrimaryModel = new QFileSystemModel(this);
    2. pSystemPrimaryModel->setRootPath(QDir::currentPath());
    3.  
    4. proxyModel->setSourceModel(pSystemPrimaryModel);
    5. proxyModel->setDynamicSortFilter(false);
    6.  
    7. // Set the QFileSystemModel model of QTreeView to display drives
    8. ui->PrimTreeView->setModel(proxyModel);
    To copy to clipboard, switch view to plain text mode 
    This displays drives in a regular manner as follows:
    Qt Code:
    1. + C:
    2. + New Volume(D:)
    3. + New Volume(E:)
    4. + SD_Card(F:)
    5. + Transcend Drive(G:
    To copy to clipboard, switch view to plain text mode 
    Basically I want to display it like follows:
    Qt Code:
    1. + Local Folder
    2. + C:
    3. + New Volume(D:)
    4. + New Volume(E:)
    5. + Removable Drives
    6. + SD_Card(F:)
    7. + Transcend Drive(G:)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sort System Drives via QSortFilterProxyModel

    QSortFilterProxyModel can only change the order to things or remove things, it can't be used to add a whole level into the three.

    I guess you'll have to write your own proxy model that can add this on top of the structure and data provided by the file system model

    Cheers,
    _

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

    Default Re: Sort System Drives via QSortFilterProxyModel

    Thanks Anda. I have been looking at it for sometime but not finding any info. It looks easy but its complicated. Any further help???

    Quote Originally Posted by anda_skoa View Post
    QSortFilterProxyModel can only change the order to things or remove things, it can't be used to add a whole level into the three.

    I guess you'll have to write your own proxy model that can add this on top of the structure and data provided by the file system model

    Cheers,
    _

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sort System Drives via QSortFilterProxyModel

    Yeah, unfortunately manipulating the structure in a proxy model is not that easy.

    I would suggest that you try to implement a simple tree model yourself first as to get a hang on how the model indexes work in tree structures.

    Like starting with a list model (subclass QAbstractListModel) and once you fnd yourself comfortable with that try an QAbstractItemModel subclass.

    Cheers,
    _

Similar Threads

  1. Display System Drives in Specific Order in QTreeView
    By owais_blore in forum Qt Programming
    Replies: 6
    Last Post: 5th December 2012, 09:07
  2. QSortFilterProxyModel : sort columns
    By Kouillo in forum Qt Programming
    Replies: 5
    Last Post: 12th September 2012, 09:44
  3. Sort huge data use QSortFilterProxyModel
    By jiaorenjie in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2011, 03:56
  4. QSortFilterProxyModel - always sort 0 to the bottom
    By ironstorm in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2008, 21:38
  5. QSortFilterProxyModel - sort strings
    By DPinLV in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2006, 02:06

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.