Results 1 to 2 of 2

Thread: Delegate for a certain item?

  1. #1

    Default Delegate for a certain item?


    I'm trying to implement something similar what you can see here

    But below the category rows (gray background) should be a treeview.

    I started to use a TreeView for all that stuff. That is, my first level children (deep 1) are the categories (gray row). Therefore I used setFirstColumnSpanned() of the tree view for these rows. Now I wanted to highlight these category rows with a different background similar to the screenshout. I created a delegate.

    The problem is: How can I say that the delegate only should be used for the category item?
    • setItemDelegate() will setup the delegate for all items
    • setItemDelegateForRow() will setup the delegate for ALL items of a certain row (but independant of the level! that is, also in a deep level I would have the delegate because the row number matches)

    Writing this an other idea comes to my mind. I could use the same delegate for all items, but in the paint() method of the delegate I would just look wheter the model index is from the first level. But this would'nt be that efficient?

    Is there another way? What about a vertical layout and every second row (of this layout!) is a treeview widget. The other rows are categories...some custom widget. But in the end the category rows should be clickable, so that the treeview can be hidden. And drag and drop between the rows should also be possible etc...

    Another related problem: how to hide the branches (and the small clickable stuff for expanding) only for the first level?

    Any hint how to proceed?

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Delegate for a certain item?

    Basically you have two choices - either make the delegate colour-aware or make the model colour-aware. For the latter simply make your model return a different colour (gray) for Qt::BackgroundRole of top-level items. If you want to implement it in the delegate, simply apply the delegate to the whole view (setItemDelegate(...)) and in the paint() routine check if the parent index is valid. If it is not, it means the item is a top-level item.

Similar Threads

  1. Item in a DLL not getting events
    By Benne Gesserit in forum Qt Programming
    Replies: 11
    Last Post: 16th August 2008, 22:30
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  3. QMovie from inside a custom item delegate
    By Crazy_Hopper in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2008, 15:18
  4. Replies: 1
    Last Post: 19th April 2007, 22:23
  5. [Qt4] Noob and custom Item Delegate
    By naresh in forum Newbie
    Replies: 36
    Last Post: 19th March 2006, 15:46


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.