Results 1 to 3 of 3

Thread: About tree organization...

  1. #1
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question About tree organization...

    Hello. I'm meeting a problem & I'll try my best to describe...

    I decide to organize my objects in a tree structure and show them in a QTreeWidget, so I put a QStandardItem as a member in each class, use a QStandardItemModel to manage them and then use QTreeView::setModel() to show them in a QTreeView.

    But now I want to get the pointer of the object which is currently selected and I don't know how... it seems QTreeView doesn't have a method to get current item, and even if it has I don't know how to get the object's pointer from the item's pointer...

    BTW, what's the difference between QTreeView & QTreeWidget? I'm totally new in GUI making...

    Thanx!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: About tree organization...

    To get the current item have a look at QAbstractItemView::selectionModel(). Second, don't put a standard item to the classed as their members. Simple construct them for the model only. And if you don't write a custom model for your needs you can receive the pointer to your object when you use QStandardItem::setData() with user role and an appropriate value.

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

    Default Re: About tree organization...

    QTreeView is model based, QTreeWidget is item based. To get selection in the tree view, access its selectionModel().
    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.


Similar Threads

  1. SQL Tree Model Help
    By MTK358 in forum Newbie
    Replies: 9
    Last Post: 22nd June 2015, 15:02
  2. Tree structure
    By ikm in forum Newbie
    Replies: 1
    Last Post: 7th August 2009, 20:19
  3. Tree Widget
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 07:31
  4. Tree View
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2009, 06:31
  5. develop a tree.
    By tkms in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2009, 04:18

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.