Using QFileSystemModel along QTreeView and QTreeWidgetItem



  • bq. -Project Main File (Always at top)
    --Project Subfile 1
    --Project Subfile 2
    --Project Subfolder 1
    ---Project Subfolder 2
    ----Project Subfile 3
    ----Project Subfolder 4
    -----Project Subfolder 5
    ------Project Subfile 4

    I have a file structure. I read the "project" path files and folders using QFileSystemModel. Then i want to display them using the structure i've posted above using QTreeWidgetItem.

    My principal issue is making the folders and their sub-folders (and maybe even sub-sub folders, let's say we can have LOT of sub-folders). And then placing the files to their correspondent folder.

    Any example / guide on how to do that job in an easy way?



  • Hi!
    Is your goal just to display it or to display it exaclty with QTreeWidget?

    If you just want to display QFileSystemModel you only need to provide a view onto this model:

    @QFileSystemModel *model = new QFileSystemModel(this);
    QTreeView *tree = new QTreeView(this);
    tree->setModel(model);@

    In case you haven't read: "nice article about model-view pattern in Qt":http://doc.qt.digia.com/main-snapshot/model-view-programming.html



  • I want to display it using Tree Model. I want to display the results from the QFileSystemModel which gives me files and folders from the path specificed.
    This is to make a "solution or project system".

    Setting the root to the main project of the file and then placing the files, folders (which it's files, and sub-folders) under the root.

    EDIT:

    What it would be is something like this:

    1. Get the files and folders from the specified root path on the QFileSystemModel
    2. Set the QTreeView root to the main project file. (aka, for example, MyProject.pro. Main file of projects)
    3. Get the all files that are in the same folder as the .pro file and add them to the Tree.
    4. Get all the folders in the same folder as the .pro file
    5. Check if inside those folder there are files and/or folders. If there are, add them. (Then if inside those sub-folders there are more folders and files, continue until the end).

    Seems to be a bit complicated and confusing.



  • Bumping the thread... Still haven't found anything to do this.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.