Important: Please read the Qt Code of Conduct -

Qt: Display Filesystem in A Customized Way inside QTreeView

  • 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);

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

    m_model = new QStandardItemModel(0,0);

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

    QList<QStandardItem *> RemovableItem;
    RemovableItem.insert(0,new QStandardItem("Removable Drives"));>setEditable(false);

    for (int i = 0; i < list.count(); i++)
    QString str =;
    Localchild = new QStandardItem(str);
    QStandardItem* LocalparentItem = m_model->item(0,0);

    QStandardItem* Removablechild = new QStandardItem();
    QStandardItem* RemovableparentItem = m_model->item(1,0);

    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

    • 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

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

Log in to reply