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>
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)
// 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:
option->palette.setCurrentColorGroup(QPalette::Inactive);
}
option->fontMetrics = QFontMetrics(font());
+ option->styleObject = const_cast<QGraphicsWidget *>(this);
}
/*!