summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qdesktopwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qdesktopwidget.cpp')
-rw-r--r--src/widgets/kernel/qdesktopwidget.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp
index ece673337a..eee818b685 100644
--- a/src/widgets/kernel/qdesktopwidget.cpp
+++ b/src/widgets/kernel/qdesktopwidget.cpp
@@ -44,6 +44,9 @@
#include "qwidget_p.h"
#include "qwindow.h"
+#include <private/qhighdpiscaling_p.h>
+#include <qpa/qplatformscreen.h>
+
QT_BEGIN_NAMESPACE
QDesktopScreenWidget::QDesktopScreenWidget(QScreen *screen, const QRect &geometry)
@@ -245,18 +248,18 @@ int QDesktopWidget::screenNumber(const QWidget *w) const
if (screens.isEmpty()) // This should never happen
return primaryScreen();
+ const QWindow *winHandle = w->windowHandle();
+ if (!winHandle) {
+ if (const QWidget *nativeParent = w->nativeParentWidget())
+ winHandle = nativeParent->windowHandle();
+ }
+
// If there is more than one virtual desktop
if (screens.count() != screens.constFirst()->virtualSiblings().count()) {
// Find the root widget, get a QScreen from it and use the
// virtual siblings for checking the window position.
- const QWidget *root = w;
- const QWidget *tmp = w;
- while ((tmp = tmp->parentWidget()))
- root = tmp;
- const QWindow *winHandle = root->windowHandle();
if (winHandle) {
- const QScreen *winScreen = winHandle->screen();
- if (winScreen)
+ if (const QScreen *winScreen = winHandle->screen())
screens = winScreen->virtualSiblings();
}
}
@@ -266,11 +269,12 @@ int QDesktopWidget::screenNumber(const QWidget *w) const
QRect frame = w->frameGeometry();
if (!w->isWindow())
frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0)));
+ const QRect nativeFrame = QHighDpi::toNativePixels(frame, winHandle);
QScreen *widgetScreen = Q_NULLPTR;
int largestArea = 0;
foreach (QScreen *screen, screens) {
- QRect intersected = screen->geometry().intersected(frame);
+ const QRect intersected = screen->handle()->geometry().intersected(nativeFrame);
int area = intersected.width() * intersected.height();
if (largestArea < area) {
widgetScreen = screen;