Hi,

I made a custom delegate to my view (list view in a icon mode).

This is a paint method of the delegate:
Qt Code:
  1. void PreviewWidget::paint(QPainter *painter, const QStyleOptionViewItem &option,
  2. const QModelIndex &index) const
  3. {
  4. painter->save();
  5.  
  6. QBrush brush;
  7. int r = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
  8. int g= ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
  9. int b = ((double)qrand()/ static_cast<double>( RAND_MAX )) * 255;
  10. brush.setColor(QColor(r,g,b));
  11. brush.setStyle(Qt::SolidPattern);
  12. painter->fillRect(option.rect, brush);
  13.  
  14. ImagePrev i;
  15. i.render(painter, option.rect.topLeft());
  16.  
  17. painter->restore();
  18. }
To copy to clipboard, switch view to plain text mode 

Results of rendering widget onto the painter is wrong. Filling painter with random color rect is only to show where widget should be located.

qt-problem.png

Why this offset occur?