PDA

View Full Version : How to activate menu bar from my app?



oficjalne100
7th March 2011, 13:03
Hi
I want make a trick. I am writing kind of text editor, and I want make as much as possible space for editing (like Chrome browser makes maximum space for www page). So I want hide menu for most time. And I want show menu when user press Qt::Key_Alt, then I want activate this menu to mimic standard Qt::Key_Alt behaviour. But suprisingly I can't find function to activate/raise menu!!! I you don't known what I mean: run any application with menu bar, and then hit ALT key, then you will see how menu is activated - I want make the same from c++ code. I was trying send event to menu bar (QEvent::KeyPress with Qt::Key_Alt), but it does not work because I filter events for menu bar, so I get infinite loop. I must filter events for menu bars, because when user again click Alt key then I want hide menu bar.

So: how to activate menu from my c++ code?

Archimedes
7th March 2011, 14:06
QMenuBar inherites QWidget, so you can just map the shortcut you want to hide() or show().

oficjalne100
7th March 2011, 14:50
I have no problem with show/hide menu. I have problem with menu activation (after showing).

Archimedes
7th March 2011, 14:53
Ohh...I got it now. I think this is the default behavior (on linux not sure about Windows). I created a project with a class inheriting QMainWindow and by pressing ALT I can access the menu bar.

oficjalne100
7th March 2011, 19:00
So far so good! One more hint: I want programicaly simulate the ALT key. I caled this behaviour as "activate menu".