Recent

Author Topic: Right justified top-level menu item?  (Read 161 times)

Zoë

  • Newbie
  • Posts: 2
Right justified top-level menu item?
« on: June 30, 2020, 01:33:13 am »
On Linux/Qt5 I'm trying to create a menu where the TMainMenu has a right justified men item (single item, not a dropdown).  Setting TMenuItem.RightJustify doesn't work. 

Looking on StackOverflow: https://stackoverflow.com/questions/25922003/set-qmenu-on-toprightcorner-in-a-qmenubar

That shows that you can do it by creating a second QMenuBar with the relevant item and then embedding it on the primary menubar with setCornerWidget.  I have that working in a trivial LCLQT project by creating it in FormCreate and toggling visibility with a button press, but I need it to attached to TMenuItem so the handles get created/freed at the right time.

To do that, I created a new TMenuItem descendant and registered a new TWSMenuItem subclass (*not* derived from TQtWSMenuItem), and I just coded the minimum necessary to create a non-TQtWidget implementation for my needs.  Specifically I override CreateHandle/DestroyHandle/AttachMenu/SetVisible, and have the HMENU it returns is a small class that keeps track of the embedded QMenuBarH and QActionH and trigger hook and just calls QMenuBar_Create/QMenuBar_addAction/QMenuBar_setCornerWidget/QMenuBar_Destroy and calls the TMenuItem's Click in a triggered hook.  It's very minimal because the menu item doesn't do anything fancy and never changes state.

That appears to be working, except that on high DPI displays depending on when the form and menu item get created, the menu item's font will be too small.  Toggling Visible after the fact, so it's recreated, makes the font the correct size.  In case it matters I'm on Mint/Cinnamon and using the Display > Settings > User interface scaling set to "Double (Hi-DPI)".  Edit: Apparently this is relevant: Using the default style in this environment (qt5ct) with the Mint/Gnome style set to Mint-Y-Dark-Blue shows the font scaling bug.  It doesn't reproduce using cleanlooks or plastique.

I know almost nothing about the LCLQT5 widgetset implementation, so I have a couple of questions:

1) Will avoiding TQtWidget like I'm doing cause problems?  Instability due to not freeing things with a delay?
2) Is there anything easy I can do to get the font correct?
3) Is there an existing alternative I missed?

If getting this working safely requires all of the TQtWSMenuItem/TQtMenu plumbing, I can make a bug tracker entry to request it for RightJustify support, but definitely can't do it myself.  Thanks!
« Last Edit: June 30, 2020, 02:57:55 am by Zoë »

 

TinyPortal © 2005-2018