bunjee
21st April 2008, 14:55
Here is two delegated QListView of 1000 items,
One is fast, the other is slow.
http://bunjeee.free.fr/slowFast.png
When the area is wider, the painting is *much* slower.
Here is my delegate paint function
void ZeChatRoom_delegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// QItemDelegate::paint(painter, option, index);
ZeChatRoom_data * chatData = index.data().value<ZeChatRoom_data *>();
// Display rects
QRect pictureRect(option.rect.x() + 2, option.rect.y() + 2, 32, 32);
QRect displayRect = QRect(option.rect.x() + 36, option.rect.y() + 2,
option.rect.width() - 38, (option.rect.height() - 4) / 2);
QRect displayRect2 = QRect(option.rect.x() + 36, option.rect.y() + option.rect.height() / 2,
option.rect.width() - 38, (option.rect.height() - 4) / 2);
QColor textColor = Qt::black;
QColor descriptionColor = ZeStyle::get()->getDarkBorderColor();
if (option.state & QStyle::State_MouseOver)
{
ZePainterController::get()->DrawHighlight(*painter, option.rect);
textColor = ZeStyle::get()->getHighlightTextColor();
descriptionColor = ZeStyle::get()->getHighlightTextColor();
ZePainterController::get()->
DrawBottomLine(*painter, option.rect, QColor(100, 100, 100, 150));
}
else
{
if (index.row() %2 == 0)
{
ZePainterController::get()->
DrawBack(*painter, option.rect, QColor(ZeStyle::get()->getBorderColor().red(),
ZeStyle::get()->getBorderColor().green(),
ZeStyle::get()->getBorderColor().blue(), 50), false);
}
ZePainterController::get()->
DrawBottomLine(*painter, option.rect,
/*QColor(100, 100, 100, 150)*/ QColor(ZeStyle::get()->getBorderColor().red(),
ZeStyle::get()->getBorderColor().green(),
ZeStyle::get()->getBorderColor().blue(), 200));
}
ZePainterController::get()->
DrawPictureRatio(*painter, *chatData->mChatPixmap, pictureRect, 1.0f);
QFont font;
font.setBold(true);
ZePainterController::get()->DrawText(*painter,
displayRect,
chatData->mRoomName + " - " + QString::number(chatData->mParticipants),
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
textColor,
&font);
ZePainterController::get()->DrawText(*painter,
displayRect2,
chatData->mDescription,
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
descriptionColor);
}
Is there a way to optimize the painting ? Especially when you're painting plain grey rectangles at each refresh.
One is fast, the other is slow.
http://bunjeee.free.fr/slowFast.png
When the area is wider, the painting is *much* slower.
Here is my delegate paint function
void ZeChatRoom_delegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// QItemDelegate::paint(painter, option, index);
ZeChatRoom_data * chatData = index.data().value<ZeChatRoom_data *>();
// Display rects
QRect pictureRect(option.rect.x() + 2, option.rect.y() + 2, 32, 32);
QRect displayRect = QRect(option.rect.x() + 36, option.rect.y() + 2,
option.rect.width() - 38, (option.rect.height() - 4) / 2);
QRect displayRect2 = QRect(option.rect.x() + 36, option.rect.y() + option.rect.height() / 2,
option.rect.width() - 38, (option.rect.height() - 4) / 2);
QColor textColor = Qt::black;
QColor descriptionColor = ZeStyle::get()->getDarkBorderColor();
if (option.state & QStyle::State_MouseOver)
{
ZePainterController::get()->DrawHighlight(*painter, option.rect);
textColor = ZeStyle::get()->getHighlightTextColor();
descriptionColor = ZeStyle::get()->getHighlightTextColor();
ZePainterController::get()->
DrawBottomLine(*painter, option.rect, QColor(100, 100, 100, 150));
}
else
{
if (index.row() %2 == 0)
{
ZePainterController::get()->
DrawBack(*painter, option.rect, QColor(ZeStyle::get()->getBorderColor().red(),
ZeStyle::get()->getBorderColor().green(),
ZeStyle::get()->getBorderColor().blue(), 50), false);
}
ZePainterController::get()->
DrawBottomLine(*painter, option.rect,
/*QColor(100, 100, 100, 150)*/ QColor(ZeStyle::get()->getBorderColor().red(),
ZeStyle::get()->getBorderColor().green(),
ZeStyle::get()->getBorderColor().blue(), 200));
}
ZePainterController::get()->
DrawPictureRatio(*painter, *chatData->mChatPixmap, pictureRect, 1.0f);
QFont font;
font.setBold(true);
ZePainterController::get()->DrawText(*painter,
displayRect,
chatData->mRoomName + " - " + QString::number(chatData->mParticipants),
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
textColor,
&font);
ZePainterController::get()->DrawText(*painter,
displayRect2,
chatData->mDescription,
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine,
descriptionColor);
}
Is there a way to optimize the painting ? Especially when you're painting plain grey rectangles at each refresh.