Results 1 to 3 of 3

Thread: QTreeView: include root in tree?

  1. #1
    Join Date
    Jun 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTreeView: include root in tree?

    I am trying to list a directory using QTreeView, but I would like to include the root in the tree (but no other files from the same level as root). In other words, assuming I am user hovercraft, what I get with
    Qt Code:
    1. QDirModel model;
    2. QTreeView tree;
    3. tree.setModel(&model);
    4. tree.setRootIndex(model.index(QDir::homePath()));
    To copy to clipboard, switch view to plain text mode 
    is:

    -bar
    -baz
    --naz
    --naznaz
    --naznaznaz
    ---todd-is-god
    -boz
    -foo


    What I want is:

    -hovercraft
    --bar
    --baz
    ---naz
    ---naznaz
    ---naznaznaz
    ----todd-is-god
    --boz
    --foo


    Is there a nobrainer way to do this?

    -M

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView: include root in tree?

    What if you set tree root index as - model.index(QDir::homePath()).parent() ??
    Will that solve ur purpose ?

  3. #3
    Join Date
    Jun 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: include root in tree?

    Quote Originally Posted by aamer4yu View Post
    What if you set tree root index as - model.index(QDir::homePath()).parent() ??
    No. That gives me:

    -bishop
    --(files inside bishop)
    -eel
    --(files inside eel)
    -hovercraft
    --bar
    --baz
    ---naz
    ---naznaz
    ---naznaznaz
    ----todd-is-god
    --boz
    --foo

    where bishop and eel are other users.

Similar Threads

  1. Replies: 1
    Last Post: 10th June 2010, 05:35
  2. Qtreeview : To get File name and path from Tree View
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2010, 13:14
  3. Direct root childs inline QTreeView
    By faraslacks in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 07:45
  4. QTreeView: make root decoration appear on visual column 0
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2008, 02:36
  5. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 18:14

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.