Results 1 to 4 of 4

Thread: Help on adding children to tree view

  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Help on adding children to tree view

    I have a TreeView and set it to a SQL model based on QAbstractItemModel.
    I want to add child items to a selected item from click event which recalls data from QSqlQueryModel.
    I can't find the method to use.
    QTreeWidgetItem has a method called addChild() but I don't know how to get the selected item from the treeView.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help on adding children to tree view

    Documentation should become your friend. Take a look at QTreeWidget class.
    It has
    Qt Code:
    1. QTreeWidgetItem * currentItem () const
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help on adding children to tree view

    QSqlQueryModel is a read-only flat model. You won't be able to add children to it. You have to provide your own model or use QTreeWidget instead of QTreeView.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help on adding children to tree view

    Quote Originally Posted by lyuts View Post
    Documentation should become your friend.
    there is soooooo much !!

    Thanks, I have solved it with wysota's reply (he seems to have all the answers)

    I read in the docs that removeChild() removes the item but not delete it.
    When the node is clicked, any existing child items will need to be removed before refreshing with a new query. Should I recursively delete them as they are removed, like in a for/while loop ?

Similar Threads

  1. Custom tree view suggestions
    By jtourville in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2009, 02:23
  2. how to update a tree view model
    By chow in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 15:27
  3. Radio buttons in a tree view
    By notwithstanding in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2008, 22:32
  4. Tree View with Icons/primitives
    By dosto.walla in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2008, 10:29
  5. Ignore mouse events out of tree view
    By krishna.bv in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:24

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.