summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qwidget.cpp20
-rw-r--r--src/widgets/kernel/qwidget_p.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 1728cfa57c..8c7e47cfdf 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -295,6 +295,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
#ifndef QT_NO_IM
, inheritsInputMethodHints(0)
#endif
+ , inSetParent(0)
#if defined(Q_WS_X11)
, picture(0)
#elif defined(Q_WS_WIN)
@@ -2568,6 +2569,22 @@ WId QWidget::effectiveWinId() const
if (id || !testAttribute(Qt::WA_WState_Created))
return id;
QWidget *realParent = nativeParentWidget();
+ if (!realParent && d_func()->inSetParent) {
+ // In transitional state. This is really just a workaround. The real problem
+ // is that QWidgetPrivate::setParent_sys (platform specific code) first sets
+ // the window id to 0 (setWinId(0)) before it sets the Qt::WA_WState_Created
+ // attribute to false. The correct way is to do it the other way around, and
+ // in that case the Qt::WA_WState_Created logic above will kick in and
+ // return 0 whenever the widget is in a transitional state. However, changing
+ // the original logic for all platforms is far more intrusive and might
+ // break existing applications.
+ // Note: The widget can only be in a transitional state when changing its
+ // parent -- everything else is an internal error -- hence explicitly checking
+ // against 'inSetParent' rather than doing an unconditional return whenever
+ // 'realParent' is 0 (which may cause strange artifacts and headache later).
+ return 0;
+ }
+ // This widget *must* have a native parent widget.
Q_ASSERT(realParent);
Q_ASSERT(realParent->internalWinId());
return realParent->internalWinId();
@@ -10080,6 +10097,7 @@ void QWidget::setParent(QWidget *parent)
void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
{
Q_D(QWidget);
+ d->inSetParent = true;
bool resized = testAttribute(Qt::WA_Resized);
bool wasCreated = testAttribute(Qt::WA_WState_Created);
QWidget *oldtlw = window();
@@ -10240,6 +10258,8 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
ancestorProxy->d_func()->embedSubWindow(this);
}
#endif
+
+ d->inSetParent = false;
}
/*!
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index e9d7682289..bb67efd090 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -769,6 +769,7 @@ public:
#ifndef QT_NO_IM
uint inheritsInputMethodHints : 1;
#endif
+ uint inSetParent : 1;
// *************************** Platform specific ************************************
#if defined(Q_WS_X11) // <----------------------------------------------------------- X11