Qt5,Qt6: fixed designing on scrolled forms. issue #41517

This commit is contained in:
zeljan1 2025-03-09 17:34:40 +01:00
parent a61fd69df0
commit 9de7888945
6 changed files with 78 additions and 16 deletions

View File

@ -290,11 +290,15 @@ var
QtDC: TQtDeviceContext absolute DC; QtDC: TQtDeviceContext absolute DC;
X, Y: Integer; X, Y: Integer;
W, H: Integer; W, H: Integer;
P: TPoint;
begin begin
if not IsValidDC(DC) then if not IsValidDC(DC) then
exit; exit;
QtDC.save; QtDC.save;
try try
P := Point(0, 0);
SetWindowOrgEx(DC, 0, 0, @P);
W := (R.Right - R.Left - 1) div DX; W := (R.Right - R.Left - 1) div DX;
H := (R.Bottom - R.Top - 1) div DY; H := (R.Bottom - R.Top - 1) div DY;

View File

@ -20114,8 +20114,15 @@ begin
Msg.PaintStruct^.hdc := FDesignContext; Msg.PaintStruct^.hdc := FDesignContext;
P := getClientOffset; P := getClientOffset;
{$IFDEF QTSCROLLABLEFORMS}
inc(P.X, -ScrollArea.horizontalScrollBar.getValue);
inc(P.Y, -ScrollArea.verticalScrollBar.getValue);
{$ELSE}
inc(P.X, FScrollX); inc(P.X, FScrollX);
inc(P.Y, FScrollY); inc(P.Y, FScrollY);
{$ENDIF}
TQtDeviceContext(Msg.DC).translate(P.X, P.Y); TQtDeviceContext(Msg.DC).translate(P.X, P.Y);
// send paint message // send paint message
@ -20157,9 +20164,13 @@ var
begin begin
if FDesignControl = nil then if FDesignControl = nil then
Exit; Exit;
// FDesignControl must be same as form area, {$IFDEF QTSCROLLABLEFORMS}
// since we use QWidget, not QMainWindow in design time. QWidget_contentsRect(ScrollArea.viewportWidget, @R);
R.Width := R.Width + ScrollArea.horizontalScrollBar.getMax;
R.Height := R.Height + ScrollArea.verticalScrollBar.getMax;
{$ELSE}
QWidget_contentsRect(Widget, @R); QWidget_contentsRect(Widget, @R);
{$ENDIF}
with R do with R do
begin begin
QWidget_move(FDesignControl, Left, Top); QWidget_move(FDesignControl, Left, Top);
@ -20309,9 +20320,7 @@ begin
{$IFDEF QTSCROLLABLEFORMS} {$IFDEF QTSCROLLABLEFORMS}
else else
if (aWidget is TQtWindowArea) then if (aWidget is TQtWindowArea) then
begin
TQtWindowArea(aWidget).scroll(XStep, YStep); TQtWindowArea(aWidget).scroll(XStep, YStep);
end;
{$ENDIF} {$ENDIF}
end else end else
begin begin
@ -20397,7 +20406,11 @@ begin
end; end;
end; end;
end; end;
QEventPaint: SlotDesignControlPaint(Sender, Event); QEventPaint:
begin
SlotDesignControlPaint(Sender, Event);
Result := True;
end;
QEventContextMenu: SlotContextMenu(Sender, Event); QEventContextMenu: SlotContextMenu(Sender, Event);
end; end;
finally finally

View File

@ -2829,7 +2829,8 @@ function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
var var
QtDC: TQtDeviceContext absolute PaintDC; QtDC: TQtDeviceContext absolute PaintDC;
Matrix: QTransformH; Matrix: QTransformH;
P: TPoint; DCScreenOrigin, P: TPoint;
Pt1, Pt2: TQtPoint;
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC)); WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC));
@ -2840,13 +2841,26 @@ begin
Matrix := QPainter_transform(QtDC.Widget); Matrix := QPainter_transform(QtDC.Widget);
OriginDiff := Point(0, 0); OriginDiff := Point(0, 0);
P := 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 if WindowHandle <> 0 then
begin
P := TQtWidget(WindowHandle).getClientOffset; P := TQtWidget(WindowHandle).getClientOffset;
P := TQtWidget(WindowHandle).MapToGlobal(P, False);
end;
if Matrix <> nil then if Matrix <> nil then
begin begin
OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X; OriginDiff.X := DCScreenOrigin.X - P.X;
OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y; OriginDiff.Y := DCScreenOrigin.Y - P.Y;
end; end;
Result := True;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -290,11 +290,15 @@ var
QtDC: TQtDeviceContext absolute DC; QtDC: TQtDeviceContext absolute DC;
X, Y: Integer; X, Y: Integer;
W, H: Integer; W, H: Integer;
P: TPoint;
begin begin
if not IsValidDC(DC) then if not IsValidDC(DC) then
exit; exit;
QtDC.save; QtDC.save;
try try
P := Point(0, 0);
SetWindowOrgEx(DC, 0, 0, @P);
W := (R.Right - R.Left - 1) div DX; W := (R.Right - R.Left - 1) div DX;
H := (R.Bottom - R.Top - 1) div DY; H := (R.Bottom - R.Top - 1) div DY;

View File

@ -20035,8 +20035,15 @@ begin
Msg.PaintStruct^.hdc := FDesignContext; Msg.PaintStruct^.hdc := FDesignContext;
P := getClientOffset; P := getClientOffset;
{$IFDEF QTSCROLLABLEFORMS}
inc(P.X, -ScrollArea.horizontalScrollBar.getValue);
inc(P.Y, -ScrollArea.verticalScrollBar.getValue);
{$ELSE}
inc(P.X, FScrollX); inc(P.X, FScrollX);
inc(P.Y, FScrollY); inc(P.Y, FScrollY);
{$ENDIF}
TQtDeviceContext(Msg.DC).translate(P.X, P.Y); TQtDeviceContext(Msg.DC).translate(P.X, P.Y);
// send paint message // send paint message
@ -20078,9 +20085,13 @@ var
begin begin
if FDesignControl = nil then if FDesignControl = nil then
Exit; Exit;
// FDesignControl must be same as form area, {$IFDEF QTSCROLLABLEFORMS}
// since we use QWidget, not QMainWindow in design time. QWidget_contentsRect(ScrollArea.viewportWidget, @R);
R.Width := R.Width + ScrollArea.horizontalScrollBar.getMax;
R.Height := R.Height + ScrollArea.verticalScrollBar.getMax;
{$ELSE}
QWidget_contentsRect(Widget, @R); QWidget_contentsRect(Widget, @R);
{$ENDIF}
with R do with R do
begin begin
QWidget_move(FDesignControl, Left, Top); QWidget_move(FDesignControl, Left, Top);
@ -20230,9 +20241,7 @@ begin
{$IFDEF QTSCROLLABLEFORMS} {$IFDEF QTSCROLLABLEFORMS}
else else
if (aWidget is TQtWindowArea) then if (aWidget is TQtWindowArea) then
begin
TQtWindowArea(aWidget).scroll(XStep, YStep); TQtWindowArea(aWidget).scroll(XStep, YStep);
end;
{$ENDIF} {$ENDIF}
end else end else
begin begin
@ -20318,7 +20327,11 @@ begin
end; end;
end; end;
end; end;
QEventPaint: SlotDesignControlPaint(Sender, Event); QEventPaint:
begin
SlotDesignControlPaint(Sender, Event);
Result := True;
end;
QEventContextMenu: SlotContextMenu(Sender, Event); QEventContextMenu: SlotContextMenu(Sender, Event);
end; end;
finally finally

View File

@ -2825,7 +2825,8 @@ function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
var var
QtDC: TQtDeviceContext absolute PaintDC; QtDC: TQtDeviceContext absolute PaintDC;
Matrix: QTransformH; Matrix: QTransformH;
P: TPoint; DCScreenOrigin, P: TPoint;
Pt1, Pt2: TQtPoint;
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC)); WriteLn('[WinAPI GetDCOriginRelativeToWindow] PaintDC ' + dbghex(PaintDC));
@ -2836,13 +2837,26 @@ begin
Matrix := QPainter_transform(QtDC.Widget); Matrix := QPainter_transform(QtDC.Widget);
OriginDiff := Point(0, 0); OriginDiff := Point(0, 0);
P := 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 if WindowHandle <> 0 then
begin
P := TQtWidget(WindowHandle).getClientOffset; P := TQtWidget(WindowHandle).getClientOffset;
P := TQtWidget(WindowHandle).MapToGlobal(P, False);
end;
if Matrix <> nil then if Matrix <> nil then
begin begin
OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X; OriginDiff.X := DCScreenOrigin.X - P.X;
OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y; OriginDiff.Y := DCScreenOrigin.Y - P.Y;
end; end;
Result := True;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------