From 42c1f472dff49cb972066d3d7a65460894bcd92e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 5 Apr 2011 13:35:30 +0200 Subject: Draw graphics item bounding rects drawn when QT_DRAW_SCENE_ITEM_RECTS=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is extremely handy to visualize bounding rects when developing pixel perfect graphics view based applications. This change makes it possible to define an environment variable (inspired by QT_FLUSH_PAINT) to enable drawing of graphics items' bounding rects with random colors. Any graphics view/declarative example can be used to test the feature. Merge-request: 981 Reviewed-by: Samuel Rødal --- src/gui/graphicsview/qgraphicsscene.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 7932a73..faa29e5 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4948,6 +4948,19 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q if (painterStateProtection || restorePainterClip) painter->restore(); + + static int drawRect = qgetenv("QT_DRAW_SCENE_ITEM_RECTS").toInt(); + if (drawRect) { + QPen oldPen = painter->pen(); + QBrush oldBrush = painter->brush(); + quintptr ptr = reinterpret_cast(item); + const QColor color = QColor::fromHsv(ptr % 255, 255, 255); + painter->setPen(color); + painter->setBrush(Qt::NoBrush); + painter->drawRect(adjustedItemBoundingRect(item)); + painter->setPen(oldPen); + painter->setBrush(oldBrush); + } } // Draw children in front -- cgit v0.12