Recent

Author Topic: Menu Text Color - Once more  (Read 419 times)

seany

  • Jr. Member
  • **
  • Posts: 99
Menu Text Color - Once more
« on: February 03, 2023, 05:21:24 pm »
I see this discussion.

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.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1195
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Menu Text Color - Once more
« Reply #1 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;
« Last Edit: February 03, 2023, 06:13:03 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

seany

  • Jr. Member
  • **
  • Posts: 99
Re: Menu Text Color - Once more
« Reply #2 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.
« Last Edit: February 03, 2023, 07:11:47 pm by seany »

zeljko

  • Hero Member
  • *****
  • Posts: 1412
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Menu Text Color - Once more
« Reply #3 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 ?

seany

  • Jr. Member
  • **
  • Posts: 99
Re: Menu Text Color - Once more
« Reply #4 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.

seany

  • Jr. Member
  • **
  • Posts: 99
Re: Menu Text Color - Once more
« Reply #5 on: February 03, 2023, 10:28:28 pm »
Please attach simple example, I'll test under Qt5/Qt6.

Sample attached

 

TinyPortal © 2005-2018