From 510ce6fa8a3a30063744eaaf004850679610060e Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 8 Apr 2009 10:27:28 +0200 Subject: BT: Fix the embedded dialogs demo on Mac OS X and Motif style The CustomProxy class installs an event filter on its child to detect whether it is shadowed by a popup or not. The problem is it does this regardless of whether it currently has a scene assigned or not. Styles that assign palettes, or otherwise cause side effects when assigned to a QGraphicsProxyWidget, will cause the demo to print warnings to the console and fail to install the event filter. The reason for the failure to install the filter is that QGraphicsItem only allows scene event filters to be installed between items that are in the same scene. So, depending on the style, you either get an ItemSceneHasChanged or an ItemChildAddedChange first. The demo must account for this, and install its filter only when the items are guaranteed to be in the scene already. Reviewed-by: Alexis --- demos/embeddeddialogs/customproxy.cpp | 17 ++++++++++++++--- demos/embeddeddialogs/customproxy.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/demos/embeddeddialogs/customproxy.cpp b/demos/embeddeddialogs/customproxy.cpp index 56a0548..dd8766f 100644 --- a/demos/embeddeddialogs/customproxy.cpp +++ b/demos/embeddeddialogs/customproxy.cpp @@ -44,7 +44,7 @@ #include CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags) - : QGraphicsProxyWidget(parent, wFlags), popupShown(false) + : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0) { timeLine = new QTimeLine(250, this); connect(timeLine, SIGNAL(valueChanged(qreal)), @@ -111,8 +111,19 @@ bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event) QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &value) { - if (change == ItemChildRemovedChange) - removeSceneEventFilter(this); + if (change == ItemChildAddedChange || change == ItemChildRemovedChange) { + if (change == ItemChildAddedChange) { + currentPopup = qVariantValue(value); + currentPopup->setCacheMode(ItemCoordinateCache); + if (scene()) + currentPopup->installSceneEventFilter(this); + } else if (scene()) { + currentPopup->removeSceneEventFilter(this); + currentPopup = 0; + } + } else if (currentPopup && change == ItemSceneHasChanged) { + currentPopup->installSceneEventFilter(this); + } return QGraphicsProxyWidget::itemChange(change, value); } diff --git a/demos/embeddeddialogs/customproxy.h b/demos/embeddeddialogs/customproxy.h index 0a5fbaf..d324426 100644 --- a/demos/embeddeddialogs/customproxy.h +++ b/demos/embeddeddialogs/customproxy.h @@ -70,6 +70,7 @@ private slots: private: QTimeLine *timeLine; bool popupShown; + QGraphicsItem *currentPopup; }; #endif -- cgit v0.12