Results 1 to 4 of 4

Thread: Model-Views: How to obtain QTreeWidgetItem from QModelIndex

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Model-Views: How to obtain QTreeWidgetItem from QModelIndex

    I have a model view with a QTreeWidget and a QAbstractItemModel in the back-end. This works fine.

    I have emitted from this widget a QModelIndex which is received by another. Is it possible to retrieve the QTreeWidgetItem that is associated with this datum?

    J.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model-Views: How to obtain QTreeWidgetItem from QModelIndex

    Either you use QTreeWidget and QTreeWidgetItems or you use QTreeView and a custom model. You can't mix them.

  3. #3
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model-Views: How to obtain QTreeWidgetItem from QModelIndex

    I am using a QTreeView and a custom model.

    indexFromItem and itemFromIndex are protected members of QTreeWidget. I need to get the model information from an item clicked in a QTree so that I can use it in another widget.

    I am having great difficulty with getting the data structure (model) information to another widget.

    J.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model-Views: How to obtain QTreeWidgetItem from QModelIndex

    If you use QTreeView, then you can't use QTreeWidget methods.

    Use QAbstractITemModel::clicked() signal to get the model index and then ask your model for data for that index.

Similar Threads

  1. Writing a Tree model.
    By kaushal_gaurav in forum Qt Programming
    Replies: 6
    Last Post: 16th January 2009, 11:22
  2. QAbstractProxyModel to do a Tree
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2008, 17:31
  3. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 18:14
  4. how to disable views from a model
    By zeeeend in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2008, 21:14
  5. Replies: 4
    Last Post: 20th September 2007, 13:11

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.