Forum > Graphics

[SOLVED} Filling a TMenuItem with colour

(1/1)

petevick:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.PopPasteDrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; AState: TOwnerDrawState);begin  ACanvas.Brush.Color := clGreen;  ACanvas.Rectangle(ARect);end; 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.

wp:
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:

--- Quote from: wp 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

--- End quote ---
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  ;)

Navigation

[0] Message Index

Go to full version