m.p
24th February 2013, 13:23
Hi,
I made a custom delegate to my view (list view in a icon mode).
This is a paint method of the delegate:
void PreviewWidget::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
painter->save();
QBrush brush;
int r = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
int g= ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
int b = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
brush.setColor(QColor(r,g,b));
brush.setStyle(Qt::SolidPattern);
painter->fillRect(option.rect, brush);
ImagePrev i;
i.render(painter, option.rect.topLeft());
painter->restore();
}
Results of rendering widget onto the painter is wrong. Filling painter with random color rect is only to show where widget should be located.
8764
Why this offset occur?
I made a custom delegate to my view (list view in a icon mode).
This is a paint method of the delegate:
void PreviewWidget::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
painter->save();
QBrush brush;
int r = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
int g= ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
int b = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
brush.setColor(QColor(r,g,b));
brush.setStyle(Qt::SolidPattern);
painter->fillRect(option.rect, brush);
ImagePrev i;
i.render(painter, option.rect.topLeft());
painter->restore();
}
Results of rendering widget onto the painter is wrong. Filling painter with random color rect is only to show where widget should be located.
8764
Why this offset occur?