Recent

Author Topic: Menu item Can't be Checked  (Read 5472 times)

guest48180

  • Guest
Menu item Can't be Checked
« on: July 08, 2018, 11:39:56 am »
I have some menu items for changing the colors of dbgrid backgrounds. Each of these have a corresponding colored bitmap. And when the user selects a color, I have it coded to check-mark the menu item selected.

The bitmap is on the left side of the menu item. That's also where the check-mark goes. And when a selection is made, the check-mark gets bumped out and doesn't show up. Is there a way to force the bitmap to the right side of the menu item? How can I fix this?

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Menu item Can't be Checked
« Reply #1 on: July 08, 2018, 12:15:33 pm »
I don't think that it is easy. There is an OnDrawItem event for the menu items, but this means you have to draw everything on your own.

What about providing two icons for each color, the standard one with a box showing the corresponding color, and another one with the same color box but a checkmark superimposed? And in the OnClick event of the menuitem you simply select the imageindex of the checked or unchecked image.

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #2 on: July 08, 2018, 12:32:57 pm »
Hahaha...I'll just leave off the check-marks. However, it'd be nice if the bitmap default position changed to the right side of the menu item so it wldn't collide with the check-marks. On all other menu systems I've seen/used, the bitmaps always defaults to the right side, check-marks to the left.

Thanks, wp.

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Menu item Can't be Checked
« Reply #3 on: July 08, 2018, 03:44:54 pm »
If you don't care about the current theme and OS style then you can draw the entire menu by yourself using the OnOwnerDraw events. Here you can do whatever you want, e.g. put the icons at the right - see attached demo. Note that the demo is not complete: The arrows indicating that a submenu is attached to an item are missing - I don't know where they should be now that the right side of the items is occupied by the icons.

I noticed that mainmenu, in particular in combination with owner-drawing, seems to have some strange behavior (which is worked around in the demo):
  • The OwnerDraw property seems to have no effect. The menu is always owner-drawn once the corresponding event handler is there.
  • How do I owner-draw the mainmenu background at the right of the last top-level menu item?
  • How do I get rid of the strange pixel at the edge of the Windows gutter in case of menu dividers? (You can see it in the demo when the dividing line (item with caption '-') is drawn 1 pixel higher, or when the Pen.Color for drawing the divider is brigher).
  • Auto-checked items with the same non-zero GroupIndex do not mutually interlock themselves.
« Last Edit: July 08, 2018, 04:01:23 pm by wp »

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #4 on: July 08, 2018, 07:01:23 pm »
I appreciate all of your input, wp. I'll look at the demo later tonight and check out what you have. I haven't ever done it the way you're talking abt, but there's always a first time. Besides sounding interesting, it might fix what's broken. Thanks again. ZzzzZzzzz time!

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Menu item Can't be Checked
« Reply #5 on: July 08, 2018, 07:35:14 pm »
AFAIK OwnerDraw menu is a Windows-only feature.

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Menu item Can't be Checked
« Reply #6 on: July 08, 2018, 07:57:17 pm »
You seem to be correct, Ondrej. My demo does not work on Linux. :(

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #7 on: July 09, 2018, 02:40:38 am »
In that case, I wonder if I shld open a bug report. To me, this isn't trivial. To me, both options shld work without colliding into one another. But that's just me.

Thanks for you help and input, wp  and Ondrej Pokorny.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Menu item Can't be Checked
« Reply #8 on: July 09, 2018, 03:10:34 am »
MenuItems on Linux+Qt4/Qt5/GTk2: when I assign some Image and Checked:=True then there is no checkbox, but the image itself is painted as "checked". Isn't it enough?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #9 on: July 09, 2018, 09:41:20 am »
@Blaazen:

Quote
when I assign some Image and Checked:=True then there is no checkbox

This isn't abt a checkbox. This is abt menu item icons and check-marks both trying to fit into to the same place, the left side of the menu item.

When I assign an icon, these are small colored squares, to the menu items (the selections are for coloring background of DBGrids), they work fine. These load to the left of menu item.

Now, if I add check-marks to show on the selected menu items and do NOT add the colored icons, then the check-marks show...on the left side of the menu item.

But, if I add the colored icons to each of the menu items AND add a check-mark to the one selected, the icon and check-mark collide, both wanting the left side of the menu item. And the check-mark loses.

Most apps I've used always have the icon on the right side, check-marks on the left. But Lazarus is placing them in the same spot. And the icon seems to take precedence over the check-mark.


wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Menu item Can't be Checked
« Reply #10 on: July 09, 2018, 09:54:43 am »
But when you occupy the right side of the menu item with the icon how do you display the menu item's key shortcut? And the indicator triangle that the item has a submenu? I find these very important things and would not like to give them up in favor of the checkmark.

Most apps I've used always have the icon on the right side, check-marks on the left.
I've never seen this...

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #11 on: July 09, 2018, 11:04:39 am »
You're right abt the kb shortcuts lining up on the right side and wld conflict with either the icon or check-mark lining up there too. Best we keep the conflict on the left between the icon and check-mark. I guess. It seems to me that if both of them have been designed to fill the same space, the left side of the menu item, then the icon shld take priority and be closest to the menu item, and the check-mark be positioned further to the left (13 pixels or so?). But I don't know how to take control of that from within my code. To me, I can deal with not having the check-mark. That's just something my gf wld like to see; this program's for her. She even asked for it. So here I am trying to give her what she wants, and I end up with the glove box fighting for the same space as the steering wheel  :D

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Menu item Can't be Checked
« Reply #12 on: July 09, 2018, 02:11:28 pm »
See screenshot: MenuItem5 and MenuItem7 are checked, the others are unchecked. It is how it works it Qt4, Qt5, GTk2 and also in Wine. Yes, they are not real checkboxes, but still fine, IMO.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #13 on: July 09, 2018, 04:47:46 pm »
Blaazen:

IMHO, I too think those are fine. But you're completely missing the point of my post. I'm talking about icons, which is what you're pic shows, and check-marks: Checked:=True;

I have small colored icons that I'm placing next to the color names on the main menu. The Blue menu item has a small blue icon next to it, on its left side. Green menu item has a green icon on its left side, etc. That works and looks good, just like the ones you showed me. But, if I choose Blue for a blue background and try to add a check-mark to it to show that's the menu item background color setting, then the check-mark (MenuItem.Checked:=True;) and the icon collide. Both want to reside to the left of the menu item. And the icons wins. The check-mark doesn't get displayed, even though I set it to be shown (MenuItem.Checked:=True;).

That's what my post is abt. For some reason the main menu was developed without taking into account that an icon and a check-mark were designed to be in the same place. So if you want an icon and a check-mark to be shown, you can forget abt it. The icon's all you'll see.

If you try to add a check-mark (menuitem.checked:=true) to one of those menu items you have in that pic, you won't see it. You'll only see the icon that you already have there.

guest48180

  • Guest
Re: Menu item Can't be Checked
« Reply #14 on: July 09, 2018, 05:38:13 pm »
And I understand what you're saying, what you're trying to show me. I'll just make a set of colored square icons with check-marks in them and change them out as needed. Not the way I wanted to do it, but I can make that work.

 

TinyPortal © 2005-2018