Faking a different DesignTimePPI to artificially zoom a form lazarus / 31-LCL ---------------------------------------------------------------------- prof7bit · 2021-09-08 07:54 I tried to zoom a form at runtime to twice its sice by entering a smaller value into DesignTimePPI than that of my development machine but Lazarus will not allow any manual change here and always replace it with the true dpi of my system. Is there any way at runtime to force or fake a different design time ppi to achieve the desired effect? ---------------------------------------------------------------------- CCRDude · 2021-09-08 08:00 Probably overkill, but something I used to spoof a different OS language to an app recently: Check how DesigntimePPI is set, hook a function behind it, return adjusted value. See https://github.com/MahdiSafsafi/DDetours Warning: there are probably easier, and better, ways to reach your goal. ---------------------------------------------------------------------- wp · 2021-09-08 08:10 https://forum.lazarus.freepascal.org/index.php/topic,54112.msg401763.h tml#msg401763 ---------------------------------------------------------------------- prof7bit · 2021-09-08 09:09 Quote from: wp on September 08, 2021, 10:10:23 amhttps://forum.lazarus .freepascal.org/index.php/topic,54112.msg401763.html#msg401763 I was really thinking that since the LCL has already implemented in all the hard stuff to scale it to whatever DPI is needed there would be an easy way to make use of this magic with a one-liner and let it do its scaling magic with a different DPI value. So far I have found only two methods to achieve what I want: write a function that iterates over all child components of a form to scale all their positions, sizes, borders and fonts, handling a bunch of ugly special cases with anchoring, making my own descendant of THintWindow that respects the scaling and having failed so far to also apply my scale to popumenususe Qt widgetset, make sure it is installed on a machine with Qt 5.12+ and then inject the environment variable QT_SCALE_FACTOR before the widgetset is initialized, this gives exceptionally pleasing results, even the scrollbars will be scaled, but it is highly platform dependent and I don't know whether it will break again in the next Qt version (it is broken for Lazarus apps in older Qt versions, although it works for other Qt apps in the same old Qt version). Since I don't know why this Qt mechanism is broken for LCL in some versions I am still using method 1 at the moment. It would be nice if this DPI scaling mechanisms could be exposed in such a way that it can be used to intentionally scale forms to "wrong" dpi values. ---------------------------------------------------------------------- paweld · 2021-09-08 09:56 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form1.ScaleBy(ToPPI, FromPPI); ---------------------------------------------------------------------- avra · 2021-09-08 23:30 Quote from: prof7bit on September 08, 2021, 09:54:43 amI tried to zoom a form at runtime to twice its sice by entering a smaller value into DesignTimePPIAs an alternative you might want to take a look at old school methods: https://forum.lazarus.freepascal.org/index.php/topic,4 0155.msg277088.html#msg277088 ---------------------------------------------------------------------- prof7bit · 2021-09-20 09:04 Quote from: paweld on September 08, 2021, 11:56:34 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form1.ScaleBy(ToPPI, FromPPI); This is almost a replacement for my previous scaling method but unfortunately ScaleBy() will not scale the anchor borders, so the spacing between controls will become much too small :-( This is how I am currently doing it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ScaleByEx(const Control: TControl; Multiplier, Divider: Integer);var  n: Integer;  WinControl: TWinControl; begin  with Control do begin    DisableAutoSizing; // prevent property changes influencing each other     Height := Height * Multiplier div Divider;    Width := Width * Multiplier div Divider;     if Assigned(Parent) then begin      Left := Left * Multiplier div Divider;      Top := Top * Multiplier div Divider;    end;     if not IsParentFont then begin      Font.Size := GetFontData(Font.Handle).Height * 72 * Multiplier        div (Font.PixelsPerInch * Divider);    end;     with BorderSpacing do begin      Left := Left * Multiplier div Divider;      Top := Top * Multiplier div Divider;      Right := Right * Multiplier div Divider;      Bottom := Bottom * Multiplier div Divider;      Around := Around * Multiplier div Divider;      InnerBorder := InnerBorder * Multiplier div Divider;    end;  end;   if Control is TWinControl then begin    WinControl:=TWinControl(Control);    if WinControl.ControlCount > 0 then begin      for n:=0 to WinControl.ControlCount-1 do begin        if WinControl.Controls[n] is TControl then begin          ScaleByEx(WinControl.Controls[n], Multiplier, Divider);        end;    end;    end;  end;  Control.EnableAutoSizing;end;