diff --git a/lcl/interfaces/qt5/qtlclintf.inc b/lcl/interfaces/qt5/qtlclintf.inc index 2d3078a696..03060ef68c 100644 --- a/lcl/interfaces/qt5/qtlclintf.inc +++ b/lcl/interfaces/qt5/qtlclintf.inc @@ -290,11 +290,15 @@ var QtDC: TQtDeviceContext absolute DC; X, Y: Integer; W, H: Integer; + P: TPoint; begin if not IsValidDC(DC) then exit; QtDC.save; try + P := Point(0, 0); + SetWindowOrgEx(DC, 0, 0, @P); + W := (R.Right - R.Left - 1) div DX; H := (R.Bottom - R.Top - 1) div DY; diff --git a/lcl/interfaces/qt5/qtwidgets.pas b/lcl/interfaces/qt5/qtwidgets.pas index 743dc7f522..095eeab912 100644 --- a/lcl/interfaces/qt5/qtwidgets.pas +++ b/lcl/interfaces/qt5/qtwidgets.pas @@ -20114,8 +20114,15 @@ begin Msg.PaintStruct^.hdc := FDesignContext; P := getClientOffset; + + {$IFDEF QTSCROLLABLEFORMS} + inc(P.X, -ScrollArea.horizontalScrollBar.getValue); + inc(P.Y, -ScrollArea.verticalScrollBar.getValue); + {$ELSE} inc(P.X, FScrollX); inc(P.Y, FScrollY); + {$ENDIF} + TQtDeviceContext(Msg.DC).translate(P.X, P.Y); // send paint message @@ -20157,9 +20164,13 @@ var begin if FDesignControl = nil then Exit; - // FDesignControl must be same as form area, - // since we use QWidget, not QMainWindow in design time. + {$IFDEF QTSCROLLABLEFORMS} + QWidget_contentsRect(ScrollArea.viewportWidget, @R); + R.Width := R.Width + ScrollArea.horizontalScrollBar.getMax; + R.Height := R.Height + ScrollArea.verticalScrollBar.getMax; + {$ELSE} QWidget_contentsRect(Widget, @R); + {$ENDIF} with R do begin QWidget_move(FDesignControl, Left, Top); @@ -20309,9 +20320,7 @@ begin {$IFDEF QTSCROLLABLEFORMS} else if (aWidget is TQtWindowArea) then - begin TQtWindowArea(aWidget).scroll(XStep, YStep); - end; {$ENDIF} end else begin @@ -20397,7 +20406,11 @@ begin end; end; end; - QEventPaint: SlotDesignControlPaint(Sender, Event); + QEventPaint: + begin + SlotDesignControlPaint(Sender, Event); + Result := True; + end; QEventContextMenu: SlotContextMenu(Sender, Event); end; finally diff --git a/lcl/interfaces/qt5/qtwinapi.inc b/lcl/interfaces/qt5/qtwinapi.inc index 98b9cb4e86..2dcfcc2676 100644 --- a/lcl/interfaces/qt5/qtwinapi.inc +++ b/lcl/interfaces/qt5/qtwinapi.inc @@ -2829,7 +2829,8 @@ function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC; var QtDC: TQtDeviceContext absolute PaintDC; Matrix: QTransformH; - P: TPoint; + DCScreenOrigin, P: TPoint; + Pt1, Pt2: TQtPoint; begin {$ifdef VerboseQtWinAPI} WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC)); @@ -2840,13 +2841,26 @@ begin Matrix := QPainter_transform(QtDC.Widget); OriginDiff := Point(0, 0); P := Point(0, 0); + DCScreenOrigin := Point(0, 0); + if (QtDC.Parent <> nil) then + begin + Pt2.X := 0; + Pt2.y := 0; + QWidget_mapToGlobal(QtDC.Parent, @Pt1, @Pt2); + DCScreenOrigin.X := Pt1.X; + DCScreenOrigin.Y := Pt1.Y; + end; if WindowHandle <> 0 then + begin P := TQtWidget(WindowHandle).getClientOffset; + P := TQtWidget(WindowHandle).MapToGlobal(P, False); + end; if Matrix <> nil then begin - OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X; - OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y; + OriginDiff.X := DCScreenOrigin.X - P.X; + OriginDiff.Y := DCScreenOrigin.Y - P.Y; end; + Result := True; end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/qt6/qtlclintf.inc b/lcl/interfaces/qt6/qtlclintf.inc index 0221d3ed4e..1e0e30838f 100644 --- a/lcl/interfaces/qt6/qtlclintf.inc +++ b/lcl/interfaces/qt6/qtlclintf.inc @@ -290,11 +290,15 @@ var QtDC: TQtDeviceContext absolute DC; X, Y: Integer; W, H: Integer; + P: TPoint; begin if not IsValidDC(DC) then exit; QtDC.save; try + P := Point(0, 0); + SetWindowOrgEx(DC, 0, 0, @P); + W := (R.Right - R.Left - 1) div DX; H := (R.Bottom - R.Top - 1) div DY; diff --git a/lcl/interfaces/qt6/qtwidgets.pas b/lcl/interfaces/qt6/qtwidgets.pas index a99adea855..60bb8cca32 100644 --- a/lcl/interfaces/qt6/qtwidgets.pas +++ b/lcl/interfaces/qt6/qtwidgets.pas @@ -20035,8 +20035,15 @@ begin Msg.PaintStruct^.hdc := FDesignContext; P := getClientOffset; + + {$IFDEF QTSCROLLABLEFORMS} + inc(P.X, -ScrollArea.horizontalScrollBar.getValue); + inc(P.Y, -ScrollArea.verticalScrollBar.getValue); + {$ELSE} inc(P.X, FScrollX); inc(P.Y, FScrollY); + {$ENDIF} + TQtDeviceContext(Msg.DC).translate(P.X, P.Y); // send paint message @@ -20078,9 +20085,13 @@ var begin if FDesignControl = nil then Exit; - // FDesignControl must be same as form area, - // since we use QWidget, not QMainWindow in design time. + {$IFDEF QTSCROLLABLEFORMS} + QWidget_contentsRect(ScrollArea.viewportWidget, @R); + R.Width := R.Width + ScrollArea.horizontalScrollBar.getMax; + R.Height := R.Height + ScrollArea.verticalScrollBar.getMax; + {$ELSE} QWidget_contentsRect(Widget, @R); + {$ENDIF} with R do begin QWidget_move(FDesignControl, Left, Top); @@ -20230,9 +20241,7 @@ begin {$IFDEF QTSCROLLABLEFORMS} else if (aWidget is TQtWindowArea) then - begin TQtWindowArea(aWidget).scroll(XStep, YStep); - end; {$ENDIF} end else begin @@ -20318,7 +20327,11 @@ begin end; end; end; - QEventPaint: SlotDesignControlPaint(Sender, Event); + QEventPaint: + begin + SlotDesignControlPaint(Sender, Event); + Result := True; + end; QEventContextMenu: SlotContextMenu(Sender, Event); end; finally diff --git a/lcl/interfaces/qt6/qtwinapi.inc b/lcl/interfaces/qt6/qtwinapi.inc index 787253a17f..adaa831b72 100644 --- a/lcl/interfaces/qt6/qtwinapi.inc +++ b/lcl/interfaces/qt6/qtwinapi.inc @@ -2825,7 +2825,8 @@ function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC; var QtDC: TQtDeviceContext absolute PaintDC; Matrix: QTransformH; - P: TPoint; + DCScreenOrigin, P: TPoint; + Pt1, Pt2: TQtPoint; begin {$ifdef VerboseQtWinAPI} WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC)); @@ -2836,13 +2837,26 @@ begin Matrix := QPainter_transform(QtDC.Widget); OriginDiff := Point(0, 0); P := Point(0, 0); + DCScreenOrigin := Point(0, 0); + if (QtDC.Parent <> nil) then + begin + Pt2.X := 0; + Pt2.y := 0; + QWidget_mapToGlobal(QtDC.Parent, @Pt1, @Pt2); + DCScreenOrigin.X := Pt1.X; + DCScreenOrigin.Y := Pt1.Y; + end; if WindowHandle <> 0 then + begin P := TQtWidget(WindowHandle).getClientOffset; + P := TQtWidget(WindowHandle).MapToGlobal(P, False); + end; if Matrix <> nil then begin - OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X; - OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y; + OriginDiff.X := DCScreenOrigin.X - P.X; + OriginDiff.Y := DCScreenOrigin.Y - P.Y; end; + Result := True; end; {------------------------------------------------------------------------------