macOS: use active window device pixel ratio for drag pixmap

In QCocoaDrag::dragPixmap, it treats QDrag::source as a QWindow, but it
is not - it's just a generic QObject* of some kind (which QQuickDrag
sets to the originating QQuickItem, and the widgets stack sets to a
QWidget). This failure means that dpr stayed at 1.0.

Unfortunately it’s not possible to receive a pointer on QWindow directly
from QQuickItem because QtWidgets and QtQuick do not share the sources,
but we can use the same dpr as current focused window has because drag
can only start from active window - press on a window which is not
focused should activate it first.

Task-number: QTBUG-57942
Change-Id: Id358c181d03d519188caaa83fb4226033b8ed1ea
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
This commit is contained in:
Oleg Yadrov 2017-01-10 15:49:54 -08:00
parent d9a2dd8d3b
commit d9c3d2301d

View File

@ -201,6 +201,10 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const
dpr = sourceWindow->devicePixelRatio();
}
#endif
else {
if (const QWindow *focusWindow = qApp->focusWindow())
dpr = focusWindow->devicePixelRatio();
}
pm = QPixmap(width * dpr, height * dpr);
pm.setDevicePixelRatio(dpr);
QPainter p(&pm);