From 93e8e2dc4b6d99b5dcc655a8f7b99e9e32188f90 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 28 Oct 2024 15:54:19 +0100 Subject: [PATCH] QGraphicsView: Fix clipping bug for rectangular custom items If an item's shape() path described a rectangle not starting at the top left corner, the code setting up clipping would correctly identify and attempt to use it as a rectangle. However the conversion to a QRectF would produce a non-normalized rectangle, which could lead to unexpected clipping results. Fix by ensuring the rect is normalized. Fixes: QTBUG-128488 Change-Id: Icbd17a95dde46a1969994f5eac021ac7b8ac5689 Reviewed-by: Paul Olav Tvete (cherry picked from commit 0cba6115605f586109a9b167a7d220670c5cda03) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/graphicsview/qgraphicsscene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index c022af6fc01..52a998add45 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -4772,7 +4772,7 @@ static inline void setClip(QPainter *painter, QGraphicsItem *item) QRectF clipRect; const QPainterPath clipPath(item->shape()); if (QPathClipper::pathToRect(clipPath, &clipRect)) - painter->setClipRect(clipRect, Qt::IntersectClip); + painter->setClipRect(clipRect.normalized(), Qt::IntersectClip); else painter->setClipPath(clipPath, Qt::IntersectClip); }