Avoid painting outside boundaries when printing QGraphicsProxyWidget

Implement clipping to widget geometry when rendering to other
paintdevices.

Fixes: QTBUG-98026
Pick-to: 6.2 5.15
Change-Id: I5652bdb8cc052ae34f05ea7963943d2b5b28e220
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Eirik Aavitsland 2021-11-08 15:42:45 +01:00
parent 851ed6f0b1
commit 1a984b3d2d

View File

@ -1576,6 +1576,10 @@ void QGraphicsProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsIt
if (exposedWidgetRect.isEmpty()) if (exposedWidgetRect.isEmpty())
return; return;
// When rendering to pdf etc. painting may go outside widget boundaries unless clipped
if (painter->device()->devType() != QInternal::Widget && (flags() & ItemClipsChildrenToShape))
painter->setClipRect(d->widget->geometry(), Qt::IntersectClip);
d->widget->render(painter, exposedWidgetRect.topLeft(), exposedWidgetRect); d->widget->render(painter, exposedWidgetRect.topLeft(), exposedWidgetRect);
} }