Results 1 to 10 of 10

Thread: C++ Tree View operation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: C++ Tree View operation

    Sorry I really don't understand what you mean...

    If you just want a ready-to-use tree structure that you can display in a couple of lines than QTreeWidget is definitely the right choice.

    If you want to create your own low-level tree structure you can use the skeleton I showed you. To display that you will have to create a custom model and set it to a QTreeView. The tree model example is a pretty good start for that.
    Current Qt projects : QCodeEdit, RotiDeCode

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

    zeeb100 (17th February 2009)

  3. #2
    Join Date
    Feb 2009
    Posts
    32
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    3

    Default Re: C++ Tree View operation

    fullmetalcoder oyu are my hero !!


    the example is perfect. on that basis I would like to add a node, delete a parent node with all children, add a child to a father. I can do it right?

  4. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: C++ Tree View operation

    Quote Originally Posted by zeeb100 View Post
    fullmetalcoder oyu are my hero !!
    My pleasure. If my answer did spare you some headbanging and hours of frustration consider using that shiny "thanks" button below the posts

    Quote Originally Posted by zeeb100 View Post
    on that basis I would like to add a node, delete a parent node with all children, add a child to a father. I can do it right?
    Sure you can. Once you have added proper methods to your node class adding/removing children is child's play. e.g :

    Qt Code:
    1. class TreeNode
    2. {
    3. public:
    4. ~TreeNode()
    5. {
    6. qDeleteAll(m_children);
    7. }
    8. void appendChild(TreeNode *c)
    9. {
    10. m_children.append(c);
    11. }
    12. void removeChild(int row)
    13. {
    14. m_children.removeAt(row);
    15. }
    16. void deleteChildRecursively(int row)
    17. {
    18. TreeNode *c = m_children.takeAt(row);
    19. delete c;
    20. }
    21. private:
    22. TreeNode *m_parent;
    23. QList<TreeNode*> m_children;
    24. };
    To copy to clipboard, switch view to plain text mode 

    Please not that the above code is just a skeleton which won't work as is (it does not deal with model/view updating for instance, which is described in the example I refered to in my previous post).
    Current Qt projects : QCodeEdit, RotiDeCode

  5. The following user says thank you to fullmetalcoder for this useful post:

    zeeb100 (17th February 2009)

  6. #4
    Join Date
    Feb 2009
    Posts
    32
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    3

    Default Re: C++ Tree View operation

    it's really hard :s

  7. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: C++ Tree View operation

    Yeah, model/view is a bit hard to master but hopefully the tutorials are quite good.

    If you need more example of custom tree model you can have a look at those I have created for use in Edyuk : https://edyuk.svn.sf.net/svnroot/edy...projectmodel2/ and https://edyuk.svn.sf.net/svnroot/edy...y/qcodemodel2/

    They are not very documented but the code is clean enough to serve as an example.
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #6
    Join Date
    Feb 2009
    Posts
    32
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    3

    Unhappy Re: C++ Tree View operation

    now i use the struct of exemple tree view ok ... but i don't do the this function

    Qt Code:
    1. class TreeNode
    2. {
    3. public:
    4. ~TreeNode()
    5. {
    6. qDeleteAll(m_children);
    7. }
    8. void appendChild(TreeNode *c)
    9. {
    10. m_children.append(c);
    11. }
    12. void removeChild(int row)
    13. {
    14. m_children.removeAt(row);
    15. }
    16. void deleteChildRecursively(int row)
    17. {
    18. TreeNode *c = m_children.takeAt(row);
    19. delete c;
    20. }
    21. private:
    22. TreeNode *m_parent;
    23. QList<TreeNode*> m_children;
    24. };
    To copy to clipboard, switch view to plain text mode 

    how can access item of model ???

    example

    insert a child in the parent specify
    Qt Code:
    1. parent_z
    2. child1
    3. child2
    4.  
    5. ......
    6. insert(child3) into parent_z
    7. ......
    8. parent_z
    9. child1
    10. child2
    11. child3
    To copy to clipboard, switch view to plain text mode 
    Last edited by zeeb100; 17th February 2009 at 16:55.

Similar Threads

  1. Radio buttons in a tree view
    By notwithstanding in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2008, 22:32
  2. Tree View with Icons/primitives
    By dosto.walla in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2008, 10:29
  3. Replies: 2
    Last Post: 18th March 2008, 15:38
  4. Ignore mouse events out of tree view
    By krishna.bv in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:24
  5. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

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
  •  
Qt is a trademark of The Qt Company.