PDA

View Full Version : Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent



Rajesh.Rathod
14th July 2015, 08:52
Dear All,

In my application, when menu with sub menu is open , programmatically sending key up/down event is not working for the submenu.

Sub menu is opened programmatically using following code


QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
QApplication::sendEvent(m_pSceneMenu, &event);

and first item of sub menu is also gets selected but after that sending further event is not working for the sub menu.

if the same time (after displaying sub menu) using arrow keys from keyboard change sub menu selections.

Please help if anyone has any idea.

Thanks.

anda_skoa
14th July 2015, 12:09
Are you sending the events to the correct recipient?

Cheers,
_

Rajesh.Rathod
14th July 2015, 14:33
If I give sub menu handle then it sends event correctly but then in case if i have more than one sub menu its very difficult to identify which sub menu is currently open because all sub menu returns true for isVisible.

Thanks

anda_skoa
14th July 2015, 14:50
Have you checked hasFocus()?

Cheers,
_

Rajesh.Rathod
15th July 2015, 07:09
You are correct, hasFocus returns false.

Sending return key press event to menu, if menu item is submenu it opens sub menu but doesn't set focus. below is the code i used to simulate return key press.


QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
QApplication::sendEvent(m_pSceneMenu, &event);

But one more important point is once the sub menu is open, after that sending key event programmatically is not working but at the same time pressing arrow keys on keyboard changes the selection on sub menu.

Thank you for your useful tips but can you suggest me something to set focus on sub menu.

Thanks.

anda_skoa
15th July 2015, 10:08
Interesting.
Normal keyboard handling requires focus, so if navigating the sub menu with the keyboard works it should have focus.

Anyway, if the focus can not be used to determine the currently open sub menu, then you'll have to decide based on which key you have sent.

Alternatively you could try sending the events to the application object and see if its overall key handling code moves focus through the menu hierarchy.

Cheers,
_