Results 1 to 6 of 6

Thread: QTreeView and custom model from QAbstractItemModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default QTreeView and custom model from QAbstractItemModel

    Hi all!

    I have created a custom model subclassing a QAbstractItemModel and inserted items with the following code:

    Qt Code:
    1. QTreeNode* root = new QTreeNode("Root", 0);
    2.  
    3. QTreeNode* n1 = new QTreeNode("N1", root);
    4.  
    5. QTreeNode* n2 = new QTreeNode("N2", root);
    6. QTreeNode* n21 = new QTreeNode("N21", n2);
    7. QTreeNode* n22 = new QTreeNode("N22", n2);
    8. QTreeNode* n23 = new QTreeNode("N23", n2);
    9.  
    10. QTreeNode* n3 = new QTreeNode("N3", root);
    11.  
    12. QTreeModel* model = new QTreeModel(this);
    13.  
    14. model->setRootNode(root);
    15.  
    16. treeFolders->setRootIsDecorated(true);
    17. treeFolders->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    What I get as result is:
    |-N1
    |-N2
    | |-N21
    | |-N22
    | |-N23
    |-N3

    How can I manage to get it this way:
    Root
    |-N1
    |-N2
    | |-N21
    | |-N22
    | |-N23
    |-N3

    I have attached a file containing my model implementation if needed for
    further examination.

    Thanks in advance!
    Attached Files Attached Files

  2. The following user says thank you to croscato for this useful post:

    geageagea (25th July 2011)

Similar Threads

  1. Custom context menu in QTreeView
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2009, 22:29
  2. Updating QTreeView with custom model
    By supergillis in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 07:01
  3. Replies: 5
    Last Post: 6th December 2007, 14:43
  4. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 13:54
  5. Add custom QTreeView in VS .NET
    By wind in forum Newbie
    Replies: 4
    Last Post: 5th October 2006, 17:04

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.