Recent

Author Topic: [SOLVED} Filling a TMenuItem with colour  (Read 517 times)

petevick

  • Sr. Member
  • ****
  • Posts: 347
[SOLVED} Filling a TMenuItem with colour
« on: November 18, 2023, 12:39:14 pm »
I want to populate a series of TMenuItems with various coloured backgrounds, no text. I have the TPopupMenu's OwnerDraw property set to True and have the following code in the MenuItems OnDrawItem event......
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PopPasteDrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. begin
  4.   ACanvas.Brush.Color := clGreen;
  5.   ACanvas.Rectangle(ARect);
  6. end;
  7.  
clGreen will eventually be replaced with a variable TColor. It seems that the OnDrawItem isn't being fired, I've placed a debug stop point in the code but it's ignored, and the MenuItem background is not green. I must be doing something fundamentally wrong, but for the life of me I can't see what it is.
« Last Edit: November 18, 2023, 04:54:57 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11902
Re: Filling a TMenuItem with colour
« Reply #1 on: November 18, 2023, 01:07:19 pm »
No, not your fault. The code works on Windows, but not on Linux, neither on gtk2 nor on qt5, also not on macOS/cocoa. But even on Windows you will not be very happy because you'd have to repaint everything yourself then: the caption, the gutter, the icons, checkmarks

petevick

  • Sr. Member
  • ****
  • Posts: 347
Re: Filling a TMenuItem with colour
« Reply #2 on: November 18, 2023, 01:13:35 pm »
No, not your fault. The code works on Windows, but not on Linux, neither on gtk2 nor on qt5, also not on macOS/cocoa. But even on Windows you will not be very happy because you'd have to repaint everything yourself then: the caption, the gutter, the icons, checkmarks
Yes, I've just found out about Windows. Unfortunately the code has to run in Linux and Windows.

With the MenuItems not having a caption, I was trying to get rid of the 'white space' to the right of the icons column, but obviously TPopupMenu doesn't have a width property, I guess I'm going to have to live with it.

Thanks for the reply wp  ;)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

 

TinyPortal © 2005-2018