Results 1 to 4 of 4

Thread: QTreeWidget how to's

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question QTreeWidget how to's

    I'm starting to put together a tree control. I need to know if I can use the same pointer to allocate the tree nodes, or if I need to keep separate variables around for each tree node?

    Example:
    Qt Code:
    1. if (pConn)
    2. {
    3. while (pConn[i].name != NULL)
    4. {
    5. QTreeWidgetItem *subItem = new QTreeWidgetItem(m_pConnectionsItem, ITEM_CONNECTIONS);
    6. subItem->setText(pConn[i].name);
    7. i++;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    Do I need separate subItems, one for each sub-item in the tree? What is the right way to do this? Does someone have some sample working code I could look at?
    - BRC
    Last edited by wysota; 6th March 2007 at 13:12. Reason: missing [code] tags

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget how to's

    Quote Originally Posted by bruccutler View Post
    I'm starting to put together a tree control. I need to
    Do I need separate subItems, one for each sub-item in the tree? What is the right way to do this? Does someone have some sample working code I could look at?
    - BRC
    http://doc.trolltech.com/4.0/itemvie...treemodel.html

    On your qt installation path have a look on xml tree sample..... /example/ /demo/

  3. #3
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget how to's

    You need to allocate a QTreeWidgetItem instance for each node in the list. Once it is inserted in the tree, the memory is owned by Qt. Only if you call ::takeItem on the tree will you again own the memory of the item that you "take" (hence it is your responsibility to free it unless you re-insert it into the tree).

    But, you don't need to keep variables to the items around, unless you intend to manipulate them for some reason. And even in that case, you no longer own the memory unless you invoke ::takeItem on the tree.

    HTH,
    Susan

  4. The following user says thank you to smacchia for this useful post:

    bruccutler (6th March 2007)

  5. #4
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Re: QTreeWidget how to's

    I have another question about tables:
    I want to be able to set an entire row all at once. As far as I can determine I have to set each individual cell one at a time.

    How do I or can I, set an entire row all at once, perhaps with a StringList?
    - BRC

Similar Threads

  1. QTreeWidget drag/drop
    By s_a_white in forum Newbie
    Replies: 1
    Last Post: 10th February 2007, 22:04
  2. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  3. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  4. How to capture resizing of QTreeWidget columns?
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 06:10
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.