Results 1 to 2 of 2

Thread: How to create root node inQDirModel

  1. #1
    Join Date
    May 2006
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Angry How to create root node inQDirModel

    Hello all,
    I want to create the tree representation of the selected directory in my file system. Currently below code is used for this:

    QDirModel model;
    model.setFilter(QDir:irs | QDir::Files);
    QTreeView tree_view;
    tree_view.setModel(&model);
    tree_view.setRootIndex(model.index("c:\myFiles"));
    tree_view.show();

    But problem with this code is that, it is not showing the selected directory as a root node. Instead, it only shows the files (and directories) presented in c:\myFiles directory. i.e. i want to view my tree structure as below

    myFiles
    │-- A.vbs
    │-- B.log
    │-- C.log
    │
    └───Test
    │-- Y.log
    â””-- X.vbs


    But i am getting the below populated structure (without root element).

    -- A.vbs
    -- B.log
    -- C.log
    └───Test
    │-- Y.log
    â””-- X.vbs

    Also i want to create tree structure of two independent folders in a single tree view in the later course of actions.
    Kindly help.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create root node inQDirModel

    Hi, does the root node show up when you don't set filters?
    And maybe you want to use QFileSystemModel, because its performance is better than QDirModel.

    Ginsengelf

Similar Threads

  1. QTreeWidget set invisible root node?
    By Braf in forum Qt Programming
    Replies: 2
    Last Post: 10th February 2013, 02:03
  2. Designing a Node Editor (Hint: Blender Node Editor)
    By Mind Calamity in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2011, 16:22
  3. Add a picture behind the QTreeView node
    By Raymond in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2010, 02:55
  4. customize the root node of a treeview
    By billconan in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 08:06
  5. how to justfy a node is leaf node or not
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2009, 07:40

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.