PDA

View Full Version : MenuBar grabs the focus on ALT pressed.



Cutey
9th January 2007, 11:24
Hi Buddies,

How do I prevent "MenuBar" from stealing the focus
when the user presses the ALT - key?

I just need under some circumstances *every* ALT - key press event to be received by the widget that has the focus without the focus being lost in between. Is it a Qt Bug?

Note:
I am using Qt 3.3.4 on Windows.

wysota
9th January 2007, 11:34
Is it a Qt Bug?

No, it's the operating system's behaviour :) Try using the other Alt key :) Remember you can always catch appropriate events by using an event filter or reimplementing event() to "steal" the key event before it is forwarded to the menu.

Cutey
11th January 2007, 10:56
By simply pressing ALT Key, the focus is grabbed by the menubar in QMainWindow,
but I dont want to handle the ALT pressed event in my widget. If I used eventfilter() for ALT pressed, this would block ShortCut functionalities too.

Expected behavior is MenuBar should have focus only for Short Cut(ALT+f, ALT+E, & etc.,) functionality not for "every" ALT pressed.

Any Suggestion ?! Thanks in Advance...

wysota
11th January 2007, 23:42
Ask Microsoft to change the system's behaviour ;)

And seriously - if you simply stop the event from being forwarded to the menu, it doesn't mean that shortcuts will seize working. The state of the alt key will still be caried in the keyEvent for the shortcut trigger. At least in theory :)

BTW. I think an event filter won't (or may not) be enough here - you may have to reimplement event() for the widget or even for the application object.

Cutey
12th January 2007, 07:46
Okey, :confused:

I have one more problem related with ALT Key.

In my application whereby the Alt key is supposed to be pressed to
enable display of underlined characters in Menu Bar.

Preferred behavior is for underlined letters which signify hot keys to be
visible at all times independent of ALT key pressed.

Is there any solution for this issue.?!

jacek
12th January 2007, 12:10
Preferred behavior is for underlined letters which signify hot keys to be
visible at all times independent of ALT key pressed.
Configure your windows to show them. In "display" properties there's a "Appearance" tab with "Effects" button (the actual names might be different, because I have a Polish version).

Cutey
16th January 2007, 06:55
Hi Jacek,

Thanks for your valuable suggestion.


Configure your windows to show them. In "display" properties there's a "Appearance" tab with "Effects" button.

But I would like to do it by the code.
For Example, In VC++ main window MenuBar you can see the underlined letters which signify hot keys visible at all times independent of the above property change.!!

wysota
16th January 2007, 10:59
For Example, In VC++ main window MenuBar you can see the underlined letters which signify hot keys visible at all times independent of the above property change.!!

It only means that it is badly implemented as it tries to be smarter than the user who should know whether he likes/wants the behaviour or not. You should think twice before trying to be too smart too.

If you insist on implementing such behaviour, you'll have to subclass QMenu and do the highlighting yourself.