summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2012-11-29 23:02:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-30 19:32:35 +0100
commitd8fcfbc3c336b76f486ce4fc215076e96ea8090c (patch)
tree962e0d052b6997f81d5d73600724c5315fa375f3 /src/widgets
parent39058bfe8e41badd9297f6eddd26008f39f9a1d8 (diff)
QGV: set QStyleOption::styleObject for graphics items & widgets
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 <andreas@hanssen.name> Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp8
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp5
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp1
3 files changed, 14 insertions, 0 deletions
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<QGraphicsWidget *>(this);
}
/*!