Results 1 to 2 of 2

Thread: Use delegate to draw different type of items

  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile Use delegate to draw different type of items

    Hi, all,
    I want to use a custom delegate to draw itemView's item, and items with different role-values should have different style, and I wish this style could be configured by QSS. I'v got that QSS cannot config single item from others, so i hope QSS config most of the items in a view, and for some special items( with a special role-value), re-implement QStyledItemDelegate : : paint(...) and draw it. However, I don't know how to change the styleoption parameter of paint(...), and I wondered why the items are drawn according to the style sheet even if i did nothing in the re-implementation of paint(...). Here is my code
    Qt Code:
    1. CustomDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)const
    2. {
    3. // if i did nothing in this function, the items are draw by the view? since they are still draw as the style sheet
    4. if (index.data(Qt::UserRole).toBool())
    5. {
    6. QStyledItemDelegate::paint(painter, option, index);
    7. }
    8. else
    9. {
    10. QStyleOption another_option(option);
    11. // here, i wonder how to change the option to change the style of this item, for example, i hope this item has the same border and font as others, but different background-color, however, this does not work:
    12. another_option.palette.setColor(QPalette::Background, QColor(Qt::yellow));
    13.  
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 


    Thanks in advance for any suggestions and help

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use delegate to draw different type of items

    For using different style for different items, you can have a look at QStylePainter documentation

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. How to draw selection in delegate
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 20:24
  3. Replies: 4
    Last Post: 9th May 2008, 21:56
  4. Model-view: Display items in different ways
    By taboom in forum Qt Programming
    Replies: 3
    Last Post: 13th August 2007, 19:05
  5. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

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.