From 291a9fd3dd4a377cd0ce567c2dea66e5669d259c Mon Sep 17 00:00:00 2001 From: zeljan1 Date: Tue, 11 Feb 2025 09:40:54 +0100 Subject: [PATCH] Qt5,Qt6: fixed distorted image creation from device (screenshoot) on HiDpi screens. --- lcl/interfaces/qt5/qtlclintf.inc | 5 +++-- lcl/interfaces/qt6/qtlclintf.inc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lcl/interfaces/qt5/qtlclintf.inc b/lcl/interfaces/qt5/qtlclintf.inc index 93151a1913..2d3078a696 100644 --- a/lcl/interfaces/qt5/qtlclintf.inc +++ b/lcl/interfaces/qt5/qtlclintf.inc @@ -755,6 +755,7 @@ var Image: QImageH; Context: TQtDeviceContext; AWnd: HWND; + APixelRatio: QReal; procedure RawImage_FromImage(AImage: QImageH); begin @@ -788,8 +789,8 @@ begin if Context.Parent <> nil then begin AWnd := HwndFromWidgetH(Context.Parent); - // AWnd should never be 0 at this point - APixmap := TQtWidget(AWnd).grabWindow(0, 0, DCSize.cx, DCSize.cy, Context.Parent); + APixelRatio := QScreen_devicePixelRatio(QWindow_screen(QWidget_windowHandle(Context.Parent))); + APixmap := TQtWidget(AWnd).grabWindow(0, 0, Round(DCSize.cx / APixelRatio), Round(DCSize.cy / APixelRatio), Context.Parent); Image := QImage_Create; QPixmap_toImage(APixmap, Image); RawImage_FromImage(Image); diff --git a/lcl/interfaces/qt6/qtlclintf.inc b/lcl/interfaces/qt6/qtlclintf.inc index c3589580e2..0221d3ed4e 100644 --- a/lcl/interfaces/qt6/qtlclintf.inc +++ b/lcl/interfaces/qt6/qtlclintf.inc @@ -774,6 +774,7 @@ var Image: QImageH; Context: TQtDeviceContext; AWnd: HWND; + APixelRatio: QReal; procedure RawImage_FromImage(AImage: QImageH); begin @@ -807,8 +808,8 @@ begin if Context.Parent <> nil then begin AWnd := HwndFromWidgetH(Context.Parent); - // AWnd should never be 0 at this point - APixmap := TQtWidget(AWnd).grabWindow(0, 0, DCSize.cx, DCSize.cy, Context.Parent); + APixelRatio := QScreen_devicePixelRatio(QWidget_screen(Context.Parent)); + APixmap := TQtWidget(AWnd).grabWindow(0, 0, Round(DCSize.cx / APixelRatio), Round(DCSize.cy / APixelRatio), Context.Parent); Image := QImage_Create; QPixmap_toImage(APixmap, Image); RawImage_FromImage(Image);