diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-09-27 11:04:48 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-11-13 16:48:13 +0000 |
commit | 02c98b7590b060430dc5ce7e5821fa13087d25f7 (patch) | |
tree | a0296bb82bbc4b09c19ea5611113e8fb0b2c83c4 | |
parent | 6fc15fa0a5ef55fbbdf7c8f66f50125a148fbea7 (diff) |
Register Window.transientParent, track user-code overriding
When QtQuick "magically" guesses the transient parent relationship
from nesting of declarations, it calls QWindow::setTransientParent(),
which has been public C++ API all along. Now there is a new
transientParent property; the setter is
QWindowPrivate::setTransientParent(), which sets a flag. If the flag
tells us that user code (e.g. QML) has set the transientParent
property, we assume the user is overriding the magic, and we can also
allow user code to set the window visible immediately, rather than
waiting for its transient parent to become visible.
Task-number: QTBUG-67903
Task-number: QTBUG-52944
Change-Id: Ia4d303263d387931d2051b2a950694a48ad5e541
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 56 | ||||
-rw-r--r-- | src/quick/items/qquickwindowmodule.cpp | 6 |
2 files changed, 61 insertions, 1 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 83a1268d1d..a09aa830fb 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -4607,6 +4607,62 @@ void QQuickWindow::resetOpenGLState() */ /*! + \qmlproperty QWindow Window::transientParent + \since 5.13 + + The window for which this window is a transient pop-up. + + This is a hint to the window manager that this window is a dialog or pop-up + on behalf of the transient parent. It usually means that the transient + window will be centered over its transient parent when it is initially + shown, that minimizing the parent window will also minimize the transient + window, and so on; however results vary somewhat from platform to platform. + + Normally if you declare a Window inside an Item or inside another Window, + this relationship is deduced automatically. In that case, if you declare + this window's \l visible property \c true, it will not actually be shown + until the \c transientParent window is shown. + + However if you set this property, then Qt Quick will no longer wait until + the \c transientParent window is shown before showing this window. If you + want to to be able to show a transient window independently of the "parent" + Item or Window within which it was declared, you can remove that + relationship by setting \c transientParent to \c null: + + \l qml + import QtQuick.Window 2.13 + + Window { + // visible is false by default + Window { + transientParent: null + visible: true + } + } + \qml + + In order to cause the window to be centered above its transient parent by + default, depending on the window manager, it may also be necessary to set + the \l Window::flags property with a suitable \l Qt::WindowType (such as + \c Qt::Dialog). +*/ + +/*! + \property QQuickWindow::transientParent + \brief The window for which this window is a transient pop-up. + \since 5.13 + + This is a hint to the window manager that this window is a dialog or pop-up + on behalf of the transient parent, which may be any kind of \l QWindow. + + In order to cause the window to be centered above its transient parent by + default, depending on the window manager, it may also be necessary to set + the \l flags property with a suitable \l Qt::WindowType (such as \c Qt::Dialog). + + \sa parent() + */ + +/*! \qmlproperty Item Window::activeFocusItem \since 5.1 diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp index ab3f49d5b6..2b109c0897 100644 --- a/src/quick/items/qquickwindowmodule.cpp +++ b/src/quick/items/qquickwindowmodule.cpp @@ -124,7 +124,8 @@ void QQuickWindowQmlImpl::componentComplete() Q_D(QQuickWindowQmlImpl); d->complete = true; QQuickItem *itemParent = qmlobject_cast<QQuickItem *>(QObject::parent()); - if (itemParent && !itemParent->window()) { + const bool transientParentAlreadySet = QQuickWindowPrivate::get(this)->transientParentPropertySet; + if (!transientParentAlreadySet && itemParent && !itemParent->window()) { qCDebug(lcTransient) << "window" << title() << "has invisible Item parent" << itemParent << "transientParent" << transientParent() << "declared visibility" << d->visibility << "; delaying show"; connect(itemParent, &QQuickItem::windowChanged, this, @@ -210,6 +211,9 @@ void QQuickWindowModule::defineModule() qmlRegisterUncreatableType<QQuickScreen,1>(uri, 2, 3, "Screen", QStringLiteral("Screen can only be used via the attached property.")); qmlRegisterUncreatableType<QQuickScreenInfo,2>(uri, 2, 3, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property.")); qmlRegisterUncreatableType<QQuickScreenInfo,10>(uri, 2, 10, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property.")); + qmlRegisterRevision<QWindow,13>(uri, 2, 13); + qmlRegisterRevision<QQuickWindow,13>(uri, 2, 13); + qmlRegisterType<QQuickWindowQmlImpl,13>(uri, 2, 13, "Window"); } QT_END_NAMESPACE |