HiDPI Drag and Drop: Properly render the default image on Mac
This is only when the attached MIME data contains text, and we fall back to rendering that text into a pixmap. It requires getting the device pixel ratio from the source which, for now, may be a QWidget or a QWindow. Other cases may exist, but that would bring more dependencies than desired. Similarly, it fixes the draggabletext example. Other examples would require either to get updated pixmaps or change substantially in order to support HiDPI (e.g., the fridgemagnets example). Change-Id: I66198214233e3e06c87505744e2aaa9691fe1bb6 Reviewed-by: Filipe Azevedo <filipe.azevedo@kdab.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
db79b89899
commit
8ebe8ae35e
@ -150,7 +150,9 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
|
||||
mimeData->setData(hotSpotMimeDataKey(),
|
||||
QByteArray::number(hotSpot.x()) + ' ' + QByteArray::number(hotSpot.y()));
|
||||
|
||||
QPixmap pixmap(child->size());
|
||||
qreal dpr = window()->windowHandle()->devicePixelRatio();
|
||||
QPixmap pixmap(child->size() * dpr);
|
||||
pixmap.setDevicePixelRatio(dpr);
|
||||
child->render(&pixmap);
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
|
@ -34,6 +34,9 @@
|
||||
#include "qcocoadrag.h"
|
||||
#include "qmacclipboard.h"
|
||||
#include "qcocoahelpers.h"
|
||||
#ifndef QT_NO_WIDGETS
|
||||
#include <QtWidgets/qwidget.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -181,7 +184,18 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const
|
||||
const int width = fm.width(s);
|
||||
const int height = fm.height();
|
||||
if (width > 0 && height > 0) {
|
||||
pm = QPixmap(width, height);
|
||||
qreal dpr = 1.0;
|
||||
if (const QWindow *sourceWindow = qobject_cast<QWindow *>(drag->source())) {
|
||||
dpr = sourceWindow->devicePixelRatio();
|
||||
}
|
||||
#ifndef QT_NO_WIDGETS
|
||||
else if (const QWidget *sourceWidget = qobject_cast<QWidget *>(drag->source())) {
|
||||
if (const QWindow *sourceWindow = sourceWidget->window()->windowHandle())
|
||||
dpr = sourceWindow->devicePixelRatio();
|
||||
}
|
||||
#endif
|
||||
pm = QPixmap(width * dpr, height * dpr);
|
||||
pm.setDevicePixelRatio(dpr);
|
||||
QPainter p(&pm);
|
||||
p.fillRect(0, 0, pm.width(), pm.height(), Qt::color0);
|
||||
p.setPen(Qt::color1);
|
||||
|
Loading…
Reference in New Issue
Block a user