Recent

Author Topic: How to customize style of TMainMenu and TPopupMenu?  (Read 1947 times)

tu

  • New Member
  • *
  • Posts: 12
How to customize style of TMainMenu and TPopupMenu?
« on: November 24, 2024, 02:17:51 pm »
I want to customize styles of TMainMenu and TPopupMenu, eg: changing menu item color.

But it seems TMainMenu and TPopupMenu are OS-dependent. I used OwnerDraw with customized OnDrawItem and OnDrawItem but it works only on Windows.

I want to customize menu styles which support cross-platform: Windows, macOS (Cocoa) and Linux (QT, GTK). Is it possible to do that?

Thank you so much,  :)

Handoko

  • Hero Member
  • *****
  • Posts: 5386
  • My goal: build my own game engine using Lazarus
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #1 on: November 24, 2024, 02:24:29 pm »
You can easily write your own popup menu. For example this is my popup with listbox in the User Interface section in the link below:
https://wiki.freepascal.org/Portal:HowTo_Demos#User_Interface

For TMainMenu, I still have no idea.

LV

  • Full Member
  • ***
  • Posts: 197
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #2 on: November 24, 2024, 08:14:09 pm »
Maybe make MainMenu something like this?
Tested on both Windows 11 and Linux(gtk2). Please take a look at the attached project.

Handoko

  • Hero Member
  • *****
  • Posts: 5386
  • My goal: build my own game engine using Lazarus
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #3 on: November 24, 2024, 08:21:49 pm »
Nice!

But things will become complicated if we need sub menus.

tu

  • New Member
  • *
  • Posts: 12
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #4 on: November 26, 2024, 02:15:00 pm »
It seems does not have any easy way to custom menu. Thank you so much :)

One more question. Is there any solution (built-in component, external libraries...) to custom draw menu?  :)

TRon

  • Hero Member
  • *****
  • Posts: 3818
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #5 on: November 26, 2024, 02:22:44 pm »
A quick search revealed this thread and it seem to be manual labour.
I do not have to remember anything anymore thanks to total-recall.

tu

  • New Member
  • *
  • Posts: 12
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #6 on: November 27, 2024, 03:21:21 am »
A quick search revealed this thread and it seem to be manual labour.

It seems OwnerDraw and OnDrawItem work only on Windows. I tested with Linux GTK and QT but OnDrawItem() has no effect.

I think have to use self-draw control or using another control to simulate popup menu.

TRon

  • Hero Member
  • *****
  • Posts: 3818
Re: How to customize style of TMainMenu and TPopupMenu?
« Reply #7 on: November 28, 2024, 03:13:53 am »
Ah, shoot ! I forgot  :-[

Yes, indeed tu, I'm sorry.
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018