Results 1 to 5 of 5

Thread: Problem with QTreeWidget.setItemDelegateForRow

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

    Default Problem with QTreeWidget.setItemDelegateForRow

    I have a QTreeWidget where I'm creating custom editing delegates for some rows in the tree that are based on field specific comboboxs. This part works fine.

    My problem is when I go to assign the editor for the row. The code I'm using is -
    Qt Code:
    1. _rowCount++;
    2. _workingTreeWidget->setItemDelegateForRow(_rowCount, comboEdit);
    To copy to clipboard, switch view to plain text mode 

    Where _rowCount is the running row counter for the rows inserted into the tree structure from the start and comboEdit is the custom editor for this row only. My problem is that this is not working correctly. What I need to know is how to retrieve the correct row number that I've inserted the QTreeWidgetItem into, so that I can set the correct delegate for it.

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

    Default Re: Problem with QTreeWidget.setItemDelegateForRow

    Not sure, but did you try QTreeWidgetItem::indexOfChild() on the parent item, or if it's a top-level item, you should be able to ask invisible root item.

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

    Default Re: Problem with QTreeWidget.setItemDelegateForRow

    A good idea, but doesn't work. After some experimenting, it didn't work and I see why.

    I'm building a multi-level tree list with a varying number of indents depending on data being presented (which is why I'm using trees). What happeans is that the delegate is inserted into a map table by row and delegate for the QTreeWidget. It is not tied to level of indenent of position from start of tree. However, when the tree is rendered, it looks like a new row counter is used every time a new level is generated.

    So if I insert a delegate somwhere in the middle of the tree at the first node after a new root node, that delegate gets applied to ALL nodes that are the first node in thier sub-trees. Thereby, duplicating my custom row editor in many, many places where I don't want it. Instead of being just the single instance that I want.

    The way I see this, this acts like a bug in the design of this class. But more likely, a lack of understanding on my part.

    ----------------------------------------
    EDIT - After I posted this, I found this in the reported bug list at http://bugreports.qt.nokia.com/browse/QTBUG-426 Dated 18 Jan 2007 and is not scheduled to be fixed. So it is time to look into another way to do this.
    Last edited by photo_tom; 25th May 2010 at 21:14.

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

    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

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

    photo_tom (2nd June 2010)

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

    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.