Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sort the System Drives in QTreeView using QSortFilterProxyModel
Qt 6.11 is out! See what's new in the release blog

Sort the System Drives in QTreeView using QSortFilterProxyModel

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

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

    Here is the code:
    @pSystemPrimaryModel = new QFileSystemModel(this);
    pSystemPrimaryModel->setRootPath(QDir::currentPath());
    pSystemPrimaryModel->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot );

    // Sets the model for the view to present.
    ui->PrimTreeView->setModel(pSystemPrimaryModel);

    // Just Display NAME and hide other Columns
    for(int nCount = 1; nCount < pSystemPrimaryModel->columnCount(); nCount++)
    ui->PrimTreeView->hideColumn(nCount);@

    This basically gives me all the drives as follows:
    @Name:

    • C:
    • New Volume(D:)
    • New Volume(E:)
    • SD_Card(F:)
    • Transcend Drive(G:) @

    Using hideColumn() I have hidden all the header(Except Name) which gets displayed when QTreeView is used i.e. Name, Type, Size etc.

    My Requirement:

    1. What I basically want to achieve is this:
      @+ Local Folder
      +C:
      +New Volume(D:)
      +New Volume(E:)
    • Removable Drives
      +SD_Card(F:)
      +Transcend Drive(G:)@

    Basically separate the local drives and external ones. I have come across QSortFilterProxyModel which looks like it sorts the drive order. But I have no clue how to use that.

    1. I want to remove the header in QTreeView. Since Name is visible in my output, I want to hide it. It would be helpful if you could guide me :)

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved