diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 83eec1e0b8..5788805ccb 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2474,9 +2474,7 @@ WId QWidget::winId() const qDebug() << "QWidget::winId: creating native window for" << this; #endif QWidget *that = const_cast(this); -#ifndef Q_WS_QPA that->setAttribute(Qt::WA_NativeWindow); -#endif that->d_func()->createWinId(); return that->data->winid; } diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index ebd618057c..ccfec7c0a1 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -184,6 +184,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) Q_Q(QWidget); Qt::WindowFlags oldFlags = data.window_flags; + bool wasCreated = q->testAttribute(Qt::WA_WState_Created); int targetScreen = -1; // Handle a request to move the widget to a particular screen @@ -196,6 +197,8 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) newparent = 0; } + setWinId(0); + if (parent != newparent) { QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function??? if (q->windowHandle()) { @@ -231,6 +234,8 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) if (!(f&Qt::Window) && (oldFlags&Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) { //qDebug() << "setParent_sys() change from toplevel"; q->destroy(); + } else if (wasCreated) { + q->createWinId(); } adjustFlags(f, q);