Results 1 to 14 of 14

Thread: How to know wich item is clicked QTreeWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to know wich item is clicked QTreeWidget

    Hi,

    Quote Originally Posted by jpn View Post
    Then you should seriously consider saying goodbye to QTreeWidget and switching to model based approach. You should wrap the internal structure into QAbstractItemModel instead of replicating it to another structure.
    Wrap the internal structure to a model is to get a model and my structure in parallel?

    Quote Originally Posted by jpn View Post
    By the way, does the internal structure of yours have any kind of identifier numbers or something like that?
    Yes, I have LinkedLists that have internal nodes with uniques ID for each node.

    Really I don't know wich is the best solution because my internal structure is handcoded (I had coded linkedLists, nodes, ... manually because it was done before I discovered Qt).

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to know wich item is clicked QTreeWidget

    Quote Originally Posted by ^NyAw^ View Post
    Wrap the internal structure to a model is to get a model and my structure in parallel?
    QAbstractItemModel subclass would itself keep no data at all. It would be a plain interface for to your internal data. That's how Qt's view classes would be able to represent your internal data without need of copying the internal data to another structure, QTreeWidgetItems in your case.

    Quote Originally Posted by ^NyAw^ View Post
    Yes, I have LinkedLists that have internal nodes with uniques ID for each node.

    Really I don't know wich is the best solution because my internal structure is handcoded (I had coded linkedLists, nodes, ... manually because it was done before I discovered Qt).
    So basically you could mark each QTreeWidgetItem with corresponding identifier:
    Qt Code:
    1. int id = ... // id of the corresponding item in the internal data structure
    2. item->setData(0, Qt::UserRole, id);
    To copy to clipboard, switch view to plain text mode 
    And once you react to clicked-signal you could ask for the identifier:
    Qt Code:
    1. int id = item->data(0, Qt::UserRole).toInt();
    2. ... // find the corresponding item in the internal data structure with help of id
    To copy to clipboard, switch view to plain text mode 
    Roles starting from Qt::UserRole and upwards can be used for application specific things. QTreeWidgetItem will be able to store them, but will of course use them for nothing by itself.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ^NyAw^ (6th November 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to know wich item is clicked QTreeWidget

    Hi,

    Hey jpn! It's so easy now!

    I just tell the item wich kind of item is, and when one is clicked, if it represents a node into a linkedList, I can tell the item parent wich position the item stays.

    Thanks for all that have replied and helped me, maybe I will ask some other questions,
    Òscar Llarch i Galán

Similar Threads

  1. QTreeWidget clicked signal
    By ^NyAw^ in forum Qt Programming
    Replies: 41
    Last Post: 30th January 2010, 11:42
  2. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 14:26
  3. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 11:23
  4. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

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.