From d8fcfbc3c336b76f486ce4fc215076e96ea8090c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 29 Nov 2012 23:02:52 +0100 Subject: QGV: set QStyleOption::styleObject for graphics items & widgets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Certain QStyle code paths expect the style object to be set. This will avoid problems when QGraphicsItems/Widgets utilize QStyle for drawing. Even if things will not necessarily animate properly, such legacy code won't cause a crash at least. Change-Id: Ic77cb4ee9820d6c4ec92c7278fd87cb866f5a780 Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Morten Johan Sørvig --- src/widgets/graphicsview/qgraphicsitem.cpp | 8 ++++++++ src/widgets/graphicsview/qgraphicsscene.cpp | 5 +++++ src/widgets/graphicsview/qgraphicswidget.cpp | 1 + 3 files changed, 14 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 70b44428f2..c30435e56a 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1315,6 +1315,14 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con option->rect = brect.toRect(); option->levelOfDetail = 1; option->exposedRect = brect; + + // Style animations require a QObject-based animation target. + // If a plain QGraphicsItem is used to draw animated controls, + // QStyle is let to send animation updates to the whole scene. + option->styleObject = q_ptr->toGraphicsObject(); + if (!option->styleObject) + option->styleObject = scene; + if (selected) option->state |= QStyle::State_Selected; if (enabled) diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 311625761c..ee65fb8fa6 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -3432,6 +3432,11 @@ bool QGraphicsScene::event(QEvent *event) // geometries that do not have an explicit style set. update(); break; + case QEvent::StyleAnimationUpdate: + // Because QGraphicsItem is not a QObject, QStyle driven + // animations are forced to update the whole scene + update(); + break; case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index 859f07a36b..c94d027cbe 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -734,6 +734,7 @@ void QGraphicsWidget::initStyleOption(QStyleOption *option) const option->palette.setCurrentColorGroup(QPalette::Inactive); } option->fontMetrics = QFontMetrics(font()); + option->styleObject = const_cast(this); } /*! -- cgit v1.2.3