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>
This commit is contained in:
parent
39058bfe8e
commit
d8fcfbc3c3
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user