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