From 2d838dd06ebacc58c620614719067f6dac5e7418 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 31 May 2016 10:03:59 +0200 Subject: Qt Designer/DnD: Take device pixel ratio of grabbed pixmaps into account. Change qtbase:ccfe33dc670a1491d9e1daa2ae17f5fe30484276 modifies QWidget::grab() to return pixmaps with device pixel ratio set when High DPI scaling is active. This caused Dnd pixmaps to have the wrong size and the widgets to change size when moved on the form due to the decoration having the wrong size. Propagate the device pixel ratio and scale sizes accordingly. Task-number: QTBUG-53713 Change-Id: I93fc5c249472913ddc4866b32d7bf2593df60635 Reviewed-by: Alessandro Portale --- src/designer/src/components/formeditor/formwindow_dnditem.cpp | 2 +- src/designer/src/lib/shared/qdesigner_dnditem.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/designer/src/components/formeditor/formwindow_dnditem.cpp b/src/designer/src/components/formeditor/formwindow_dnditem.cpp index 3463d50e6..a39c0d0fb 100644 --- a/src/designer/src/components/formeditor/formwindow_dnditem.cpp +++ b/src/designer/src/components/formeditor/formwindow_dnditem.cpp @@ -53,7 +53,7 @@ static QWidget *decorationFromWidget(QWidget *w) QLabel *label = new QLabel(0, Qt::ToolTip); QPixmap pm = w->grab(QRect(0, 0, -1, -1)); label->setPixmap(pm); - label->resize(pm.size()); + label->resize((QSizeF(pm.size()) / pm.devicePixelRatio()).toSize()); return label; } diff --git a/src/designer/src/lib/shared/qdesigner_dnditem.cpp b/src/designer/src/lib/shared/qdesigner_dnditem.cpp index 5ed17a014..b56313211 100644 --- a/src/designer/src/lib/shared/qdesigner_dnditem.cpp +++ b/src/designer/src/lib/shared/qdesigner_dnditem.cpp @@ -137,6 +137,7 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag const QPixmap widgetPixmap = deco->grab(QRect(0, 0, -1, -1)); #ifdef TRANSPARENT_DRAG_PIXMAP QImage image(widgetPixmap.size(), QImage::Format_ARGB32); + image.setDevicePixelRatio(widgetPixmap.devicePixelRatio()); image.fill(QColor(Qt::transparent).rgba()); QPainter painter(&image); painter.drawPixmap(QPoint(0, 0), widgetPixmap); @@ -153,13 +154,17 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag const QDesignerDnDItems::const_iterator cend = m_items.constEnd(); QDesignerDnDItems::const_iterator it =m_items.constBegin(); QRect unitedGeometry = (*it)->decoration()->geometry(); + const qreal devicePixelRatio = (*it)->decoration()->devicePixelRatioF(); for (++it; it != cend; ++it ) unitedGeometry = unitedGeometry .united((*it)->decoration()->geometry()); // paint with offset. At the same time, create a mask bitmap, containing widget rectangles. - QImage image(unitedGeometry.size(), QImage::Format_ARGB32); + const QSize imageSize = (QSizeF(unitedGeometry.size()) * devicePixelRatio).toSize(); + QImage image(imageSize, QImage::Format_ARGB32); + image.setDevicePixelRatio(devicePixelRatio); image.fill(QColor(Qt::transparent).rgba()); - QBitmap mask(unitedGeometry.size()); + QBitmap mask(imageSize); + mask.setDevicePixelRatio(devicePixelRatio); mask.clear(); // paint with offset, determine action QPainter painter(&image); @@ -170,7 +175,7 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag const QPixmap wp = w->grab(QRect(0, 0, -1, -1)); const QPoint pos = w->pos() - decorationTopLeft; painter.drawPixmap(pos, wp); - maskPainter.fillRect(QRect(pos, wp.size()), Qt::color1); + maskPainter.fillRect(QRect(pos, w->size()), Qt::color1); } painter.end(); maskPainter.end(); -- cgit v1.2.1