QDialog: Pass transient parent as a parent to native dialogs

Sometimes it's needed to show a native dialog for another process,
for example in xdg-desktop-portal-kde. In this case we have WId
of a parent window which can be used for calling
QWindow::setTransientParent(QWindow::fromWinId(...)).

Pass this transient parent to a native dialog so it could use
it as a transient parent for itself. Rename
QDialogPrivate::parentWindow() for clarity.

Change-Id: I68974ddea35f9366a0ddffe602d9d028f45e26fa
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Alexander Volkov 2018-12-18 16:49:20 +03:00
parent ff835a5030
commit f05cc4144e
2 changed files with 7 additions and 4 deletions

View File

@ -145,10 +145,13 @@ bool QDialogPrivate::canBeNativeDialog() const
return false; return false;
} }
QWindow *QDialogPrivate::parentWindow() const QWindow *QDialogPrivate::transientParentWindow() const
{ {
if (const QWidget *parent = q_func()->nativeParentWidget()) Q_Q(const QDialog);
if (const QWidget *parent = q->nativeParentWidget())
return parent->windowHandle(); return parent->windowHandle();
else if (q->windowHandle())
return q->windowHandle()->transientParent();
return 0; return 0;
} }
@ -158,7 +161,7 @@ bool QDialogPrivate::setNativeDialogVisible(bool visible)
if (visible) { if (visible) {
Q_Q(QDialog); Q_Q(QDialog);
helperPrepareShow(helper); helperPrepareShow(helper);
nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), parentWindow()); nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), transientParentWindow());
} else if (nativeDialogInUse) { } else if (nativeDialogInUse) {
helper->hide(); helper->hide();
} }

View File

@ -87,7 +87,7 @@ public:
{} {}
~QDialogPrivate(); ~QDialogPrivate();
QWindow *parentWindow() const; QWindow *transientParentWindow() const;
bool setNativeDialogVisible(bool visible); bool setNativeDialogVisible(bool visible);
QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const; QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const;
void deletePlatformHelper(); void deletePlatformHelper();