Results 1 to 5 of 5

Thread: Problem with QTreeWidget.setItemDelegateForRow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Munich
    Posts
    32
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 8 Times in 6 Posts

    Default Re: Problem with QTreeWidget.setItemDelegateForRow

    Okay. Seems you have different data types on different hierarchies on your tree. One option I could see would be to have the item delegate be aware of the models item type. Here are the steps:

    (1) Define a new ItemRole e.g enum { TypeRole = Qt::UserRole + 1 };
    (2) Define an enums on the types you want to differentiate between
    (3) For each tree item set your type with setData(TypeRole, YourType);
    (4) Create a CustomItemDelegate and create your editor based on your type (you get an index as a parameter, just ask the index.data(TypeRole).toInt() to get your type back

    Not sure how else to transport custom type information from model over to the delegate. Please let me know if this works. Thanks

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

    photo_tom (2nd June 2010)

  3. #2
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: Problem with QTreeWidget.setItemDelegateForRow

    The custom user role was a good idea, but I could not make it work. Still not sure why.

    However, while looking at the star delegate demo app, I saw that it used a custom variant data type. So I re-wrote things to that I had a custom data type that transfer both desired index for the combobox and the stringlist to generate the combobox from. Once I did this and then line for line adapted the demo app, I got things to work.

    So for now, I think the only way to do this is
    1 - Assign a editing delegate to the entire column
    2 - In that delegate, when a custom data type is found, generate the correct editing control for your needs.

Similar Threads

  1. QTreeWidget + StyleSheet problem
    By BlackHornet in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2009, 20:16
  2. QTreeWidget + Persistent Editor problem
    By Stephen Yee in forum Qt Programming
    Replies: 0
    Last Post: 6th May 2008, 17:25
  3. problem in QTreewidget
    By jyoti in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2006, 11:04
  4. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  5. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47

Tags for this Thread

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.