diff options
Diffstat (limited to 'src/printsupport/dialogs/qprintdialog_win.cpp')
-rw-r--r-- | src/printsupport/dialogs/qprintdialog_win.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp index 9d662d2e8e..6d8c2d0f4d 100644 --- a/src/printsupport/dialogs/qprintdialog_win.cpp +++ b/src/printsupport/dialogs/qprintdialog_win.cpp @@ -42,7 +42,7 @@ public: QWin32PrintEnginePrivate *ep; }; -static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, +static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWindow *parentWindow, QPrintDialog *pdlg, QPrintDialogPrivate *d, HGLOBAL *tempDevNames) { @@ -101,9 +101,12 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (d->ep->printToFile) pd->Flags |= PD_PRINTTOFILE; - Q_ASSERT(parent); - QWindow *parentWindow = parent->windowHandle(); - pd->hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0; + + WId wId = parentWindow ? parentWindow->winId() : 0; + //QTBUG-118899 PrintDlg needs valid window handle in hwndOwner + //So in case there is no valid handle in the application, + //use the desktop as valid handle. + pd->hwndOwner = wId != 0 ? HWND(wId) : GetDesktopWindow(); pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; pd->nCopies = d->printer->copyCount(); @@ -182,15 +185,20 @@ int QPrintDialog::exec() int QPrintDialogPrivate::openWindowsPrintDialogModally() { Q_Q(QPrintDialog); - QWidget *parent = q->parentWidget(); - if (parent) - parent = parent->window(); - else - parent = QApplication::activeWindow(); - - // If there is no window, fall back to the print dialog itself - if (parent == 0) - parent = q; + QWindow *parentWindow = q->windowHandle() ? q->windowHandle()->transientParent() : nullptr; + if (!parentWindow) { + QWidget *parent = q->parentWidget(); + if (parent) + parent = parent->window(); + else + parent = QApplication::activeWindow(); + + // If there is no window, fall back to the print dialog itself + if (!parent) + parent = q; + + parentWindow = parent->windowHandle(); + } q->QDialog::setVisible(true); @@ -205,7 +213,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() memset(&pd, 0, sizeof(PRINTDLGEX)); pd.lStructSize = sizeof(PRINTDLGEX); pd.lpPageRanges = &pageRange; - qt_win_setup_PRINTDLGEX(&pd, parent, q, this, tempDevNames); + qt_win_setup_PRINTDLGEX(&pd, parentWindow, q, this, tempDevNames); do { done = true; |