1 Attachment(s)
QWidget::render() paint to painter with wrong offset.
Hi,
I made a custom delegate to my view (list view in a icon mode).
This is a paint method of the delegate:
Code:
{
painter->save();
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.
Attachment 8764
Why this offset occur?
Re: QWidget::render() paint to painter with wrong offset.
Quote:
Why this offset occur?
Probably because you are passing option.rect.topLeft() into the render() call instead of (0,0).
Re: QWidget::render() paint to painter with wrong offset.
But option.rect.topLeft() is a good position for every item. First will get (0,0), next will get another position according to size of a item (given by sizeHint()). So unfortunately your comment is very wrong.
Re: QWidget::render() paint to painter with wrong offset.
Here's a bug report on this: QTBUG-26694
Try the workaround in the attachment:
Code:
i.render( painter, painter->deviceTransform().map(option.rect.topLeft()));
Re: QWidget::render() paint to painter with wrong offset.
Quote:
Originally Posted by
norobro
Here's a bug report on this:
QTBUG-26694
Try the workaround in the attachment:
Code:
i.render( painter, painter->deviceTransform().map(option.rect.topLeft()));
It works. Thanks a lot! :)