Here is two delegated QListView of 1000 items,
One is fast, the other is slow.



When the area is wider, the painting is *much* slower.

Here is my delegate paint function
Qt Code:
  1. void ZeChatRoom_delegate::paint(QPainter *painter,
  2. const QStyleOptionViewItem &option,
  3. const QModelIndex &index) const
  4. {
  5. // QItemDelegate::paint(painter, option, index);
  6.  
  7. ZeChatRoom_data * chatData = index.data().value<ZeChatRoom_data *>();
  8.  
  9. // Display rects
  10. QRect pictureRect(option.rect.x() + 2, option.rect.y() + 2, 32, 32);
  11.  
  12. QRect displayRect = QRect(option.rect.x() + 36, option.rect.y() + 2,
  13. option.rect.width() - 38, (option.rect.height() - 4) / 2);
  14.  
  15. QRect displayRect2 = QRect(option.rect.x() + 36, option.rect.y() + option.rect.height() / 2,
  16. option.rect.width() - 38, (option.rect.height() - 4) / 2);
  17.  
  18. QColor textColor = Qt::black;
  19. QColor descriptionColor = ZeStyle::get()->getDarkBorderColor();
  20.  
  21. if (option.state & QStyle::State_MouseOver)
  22. {
  23. ZePainterController::get()->DrawHighlight(*painter, option.rect);
  24.  
  25. textColor = ZeStyle::get()->getHighlightTextColor();
  26. descriptionColor = ZeStyle::get()->getHighlightTextColor();
  27.  
  28. ZePainterController::get()->
  29. DrawBottomLine(*painter, option.rect, QColor(100, 100, 100, 150));
  30. }
  31. else
  32. {
  33. if (index.row() %2 == 0)
  34. {
  35. ZePainterController::get()->
  36. DrawBack(*painter, option.rect, QColor(ZeStyle::get()->getBorderColor().red(),
  37. ZeStyle::get()->getBorderColor().green(),
  38. ZeStyle::get()->getBorderColor().blue(), 50), false);
  39. }
  40.  
  41. ZePainterController::get()->
  42. DrawBottomLine(*painter, option.rect,
  43. /*QColor(100, 100, 100, 150)*/ QColor(ZeStyle::get()->getBorderColor().red(),
  44. ZeStyle::get()->getBorderColor().green(),
  45. ZeStyle::get()->getBorderColor().blue(), 200));
  46. }
  47.  
  48. ZePainterController::get()->
  49. DrawPictureRatio(*painter, *chatData->mChatPixmap, pictureRect, 1.0f);
  50.  
  51. QFont font;
  52. font.setBold(true);
  53. ZePainterController::get()->DrawText(*painter,
  54. displayRect,
  55. chatData->mRoomName + " - " + QString::number(chatData->mParticipants),
  56. Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
  57. textColor,
  58. &font);
  59.  
  60. ZePainterController::get()->DrawText(*painter,
  61. displayRect2,
  62. chatData->mDescription,
  63. Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
  64. descriptionColor);
  65. }
To copy to clipboard, switch view to plain text mode 

Is there a way to optimize the painting ? Especially when you're painting plain grey rectangles at each refresh.