From b6a59c00e90116e968fd3fc911592d23fdf8f42f Mon Sep 17 00:00:00 2001 From: Maxim Ganetsky Date: Tue, 30 Apr 2024 18:43:30 +0000 Subject: [PATCH] Qt: Fixed menus backed by multi-resolution image lists always using the 96ppi image rather than the resolution-specific one. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing code attempts to use/overwrite the preexisting AMenuItem.Bitmap property, but the ImageList.ResolutionForPPI.GetBitmap call triggers TMenuItem.BitmapChange, which frees the updated image. The subsequent setImage(AMenuItem.Bitmap.Handle) call then goes through its standard behavior again, which is to always retrieve the 96ppi variant. (cherry picked from commit 532ecb2653d8253f1e2555291afcd5970a4c2c2a) Co-authored-by: Zoƫ Peterson --- lcl/interfaces/qt/qtwsmenus.pp | 9 +++++++-- lcl/interfaces/qt5/qtwsmenus.pp | 9 +++++++-- lcl/interfaces/qt6/qtwsmenus.pp | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lcl/interfaces/qt/qtwsmenus.pp b/lcl/interfaces/qt/qtwsmenus.pp index 548816e539..62c46829dc 100644 --- a/lcl/interfaces/qt/qtwsmenus.pp +++ b/lcl/interfaces/qt/qtwsmenus.pp @@ -136,8 +136,13 @@ begin if (ImgList <> nil) and (AMenuItem.ImageIndex >= 0) and (AMenuItem.ImageIndex < ImgList.Count) then begin - ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, AMenuItem.Bitmap); // Qt bindings support only 16px icons for menu items - Result.setImage(TQtImage(AMenuItem.Bitmap.Handle)); + Bmp := TBitmap.Create; + try + ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, Bmp); // Qt bindings support only 16px icons for menu items + Result.setImage(TQtImage(Bmp.Handle)); + finally + Bmp.Free; + end; end else if Assigned(AMenuItem.Bitmap) then begin diff --git a/lcl/interfaces/qt5/qtwsmenus.pp b/lcl/interfaces/qt5/qtwsmenus.pp index 1e2f53d70f..2a3a83d87b 100644 --- a/lcl/interfaces/qt5/qtwsmenus.pp +++ b/lcl/interfaces/qt5/qtwsmenus.pp @@ -135,8 +135,13 @@ begin if (ImgList <> nil) and (AMenuItem.ImageIndex >= 0) and (AMenuItem.ImageIndex < ImgList.Count) then begin - ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, AMenuItem.Bitmap); // Qt bindings support only 16px icons for menu items - Result.setImage(TQtImage(AMenuItem.Bitmap.Handle)); + Bmp := TBitmap.Create; + try + ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, Bmp); // Qt bindings support only 16px icons for menu items + Result.setImage(TQtImage(Bmp.Handle)); + finally + Bmp.Free; + end; end else if Assigned(AMenuItem.Bitmap) then begin diff --git a/lcl/interfaces/qt6/qtwsmenus.pp b/lcl/interfaces/qt6/qtwsmenus.pp index ec54144d37..47d50dd9b3 100644 --- a/lcl/interfaces/qt6/qtwsmenus.pp +++ b/lcl/interfaces/qt6/qtwsmenus.pp @@ -135,8 +135,13 @@ begin if (ImgList <> nil) and (AMenuItem.ImageIndex >= 0) and (AMenuItem.ImageIndex < ImgList.Count) then begin - ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, AMenuItem.Bitmap); // Qt bindings support only 16px icons for menu items - Result.setImage(TQtImage(AMenuItem.Bitmap.Handle)); + Bmp := TBitmap.Create; + try + ImgList.ResolutionForPPI[16, ScreenInfo.PixelsPerInchX, 1].GetBitmap(AMenuItem.ImageIndex, Bmp); // Qt bindings support only 16px icons for menu items + Result.setImage(TQtImage(Bmp.Handle)); + finally + Bmp.Free; + end; end else if Assigned(AMenuItem.Bitmap) then begin