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. Qt: Display Filesystem in A Customized Way inside QTreeView
Forum Updated to NodeBB v4.3 + New Features

Qt: Display Filesystem in A Customized Way inside QTreeView

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k 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 am working on Qt app where I need to display Filesystem inside a Qtreeview. Basically my idea is to customize the filesystem in such a way that Removable Drives come under one section and Local Drives come under another. I tried to achieve it using QFSFileEngine but I have been successful to some extent. here is the code:
    @pSystemSecondaryModel = new QFileSystemModel(this);
    pSystemSecondaryModel->setRootPath(QDir::currentPath());

    list = QFSFileEngine::drives();
    for(int i = 0; i < list.size(); i++)
    {
    qDebug() << list.at(i).absoluteDir();
    }

    m_model = new QStandardItemModel(0,0);

    QList<QStandardItem *> LocalItem;
    LocalItem.insert(0,new QStandardItem("Local Drives"));
    LocalItem.at(0)->setEditable(false);
    m_model->insertRow(0,LocalItem);

    QList<QStandardItem *> RemovableItem;
    RemovableItem.insert(0,new QStandardItem("Removable Drives"));
    RemovableItem.at(0)->setEditable(false);
    m_model->insertRow(1,RemovableItem);

    for (int i = 0; i < list.count(); i++)
    {
    QString str = list.at(i).absolutePath();
    Localchild = new QStandardItem(str);
    QStandardItem* LocalparentItem = m_model->item(0,0);
    Localchild->setEditable(false);
    LocalparentItem->appendRow(Localchild);
    }

    QStandardItem* Removablechild = new QStandardItem();
    QStandardItem* RemovableparentItem = m_model->item(1,0);
    Removablechild->setEditable(false);
    RemovableparentItem->appendRow(Removablechild);
    ui->PrimTreeView->setModel(m_model);@

    When I run the app, it shows Local Drives and Removable Drives root node. Under Local Drive node, I find all C: D: E: etc as children whereas Removable Drive seems to be empty i.e. without any children. Here is the scenario which is the current output:
    @- Local Drives
    C:/
    D:/
    E:/

    • Removable Drives@

    But when I click on each drive, I am not able to see the subdirectories at all because I am not passing the Filesystem instance inside SetModel. If I do that, it displays all the drives which is something I don want. Ideally with this approach above, when I click C:/ i should be able to see Windows, Program Files folder etc. Its totally empty. How can I achieve it? Please help

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Stoned Jesus
      wrote on last edited by
      #2

      I think the only way is to just subclass QStandardItemModel (or QAbstractItemModel) and do the file system listings instead of using QFileSystemModel. But it looks complicated. Can anyone help me achieve this?

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