Results 1 to 3 of 3

Thread: How to get parent of selected item in TreeView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get parent of selected item in TreeView?

    Qt Code:
    1. QTreeWidgetItem *item = treeWidget->currentItem();
    2. value = item->data();
    3. QTreeWidgetItem *item_parent = item->parent();
    4. if (item_parent) ....
    To copy to clipboard, switch view to plain text mode 

    I suggest not to use the "DisplayRole" here.
    I would add a custom role for each item that contains the QDate so you don't have to build up dates from displayed data. Maybe another role that tells you if it is a year/month/day item.
    (You just have to figure out how you represent months and so on (a QDate can't have a day value of 0.)

    HTH

  2. The following user says thank you to caduel for this useful post:

    RavenS (7th March 2009)

  3. #2
    Join Date
    Feb 2009
    Location
    Russia, Siberia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get parent of selected item in TreeView?

    Huh, thank you very much! I just didn't saw this method.

    And also thanks for suggestion, I'll think about it.

Similar Threads

  1. Replies: 4
    Last Post: 25th September 2008, 13:54
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  3. current item in treeview
    By kernel_panic in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 19:26
  4. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09
  5. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00

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.