Lazarus

Programming => General => Topic started by: seany on February 03, 2023, 05:21:24 pm

Title: Menu Text Color - Once more
Post by: seany on February 03, 2023, 05:21:24 pm
I see this discussion (https://forum.lazarus.freepascal.org/index.php?topic=53234.0).

So I tried this;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItem1DrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. var
  4.   s: string;
  5. begin
  6.  
  7.   ACanvas.Font.Color := clYellow;
  8.  
  9.   ACanvas.Brush.Color := clBlack;
  10.   ACanvas.Rectangle(ARect);
  11.  
  12.   s := (Sender as TMenuItem).Caption;
  13.  
  14.   ACanvas.FillRect(ARect);
  15.   ACanvas.TextRect(ARect, ARect.Left+2, ARect.Top+2,s);
  16.  
  17. end;
  18.  
  19. procedure TForm1.MenuItem1MeasureItem(Sender: TObject; ACanvas: TCanvas;
  20.   var AWidth, AHeight: Integer);
  21.  
  22. begin
  23.   ACanvas.Font.Name := 'Liberation Mono';
  24.   ACanvas.Font.Size := 12;
  25.   AWidth := ACanvas.TextWidth(TMenuItem(Sender).Caption);
  26.   AHeight := ACanvas.TextHeight('Tg');
  27. end;
  28.          

Note that ownerdraw is set to true for main menu in form designer.

Sadly, Absolutely no effect.

I am on Linux with QT5.
Details: Lazarus 2.2.4 (rev Unknown) FPC 3.2.2 x86_64-linux-qt5

Please Help.
Title: Re: Menu Text Color - Once more
Post by: KodeZwerg on February 03, 2023, 05:53:13 pm
Will this have the effect you want to have?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
  2.   ARect: TRect; AState: TOwnerDrawState);
  3. begin
  4.   ACanvas.Brush.Color := clBlack;
  5.   ACanvas.FillRect(ARect);
  6.   ACanvas.Font.Color := clYellow;
  7.   ACanvas.TextOut(ARect.Left, ARect.Top, TMenuItem(Sender).Caption);
  8. end;
Title: Re: Menu Text Color - Once more
Post by: seany on February 03, 2023, 07:04:48 pm
Exactly, this, as in your picture.
But in my case, the menu font remains black color

See, the top menu is from the Lazarus IDE. it picks up the system menu setting.

The bottom menu is the app i am writing, where I have currently put in your code. It is black

Also it does not matter, if I put the code you supplied in MainMenu1.drawItem or MenuItem1.drawItem, in both cases, menu font color is black.
Title: Re: Menu Text Color - Once more
Post by: zeljko on February 03, 2023, 09:47:16 pm
Please attach simple example, I'll test under Qt5/Qt6. It should work afair, but I've used custom painting only for TPopupMenu, never for mainmenu.
EDIT: Is it only for mainmenu main items ? Or submenus looks good ?
Title: Re: Menu Text Color - Once more
Post by: seany on February 03, 2023, 10:22:13 pm
Okey, I will prepare a minimal system.

Submenu looks fine. Submenu can also pick up system theme colors. MainMenu top level items can't.
Title: Re: Menu Text Color - Once more
Post by: seany on February 03, 2023, 10:28:28 pm
Please attach simple example, I'll test under Qt5/Qt6.

Sample attached
TinyPortal © 2005-2018