horbi
26th July 2013, 14:33
Hi,
I'm working on a piece of software (on Linux/X11), which uses Qt application menus with simulated keyboard inputs and no mouse.
Simulating keyboard inputs works with:
QKeyEvent keyEvent(QEvent::KeyPress,Qt::Key_Tab, Qt::NoModifier);
QWidget* pWidget = qApp->activeWindow()->focusWidget();
qApp->sendEvent(pWidget, &keyEvent);
… for tab input or:
QKeyEvent keyEvent(QEvent::KeyPress,Qt::Key_..., Qt::NoModifier);
QWidget* pWidget = qApp->activePopupWidget();
qApp->sendEvent(pWidget, &keyEvent);
… for other keys
But I always have to use the mouse to get an initial highlighted menu item. I tried a lot of things to get this highlighted item by program input.
With Qmenu::exec() I succeded to open a popup menu but could not get a highlighted item there, so the simulated inputs have no effect.
What am I doing wrong?
I'm working on a piece of software (on Linux/X11), which uses Qt application menus with simulated keyboard inputs and no mouse.
Simulating keyboard inputs works with:
QKeyEvent keyEvent(QEvent::KeyPress,Qt::Key_Tab, Qt::NoModifier);
QWidget* pWidget = qApp->activeWindow()->focusWidget();
qApp->sendEvent(pWidget, &keyEvent);
… for tab input or:
QKeyEvent keyEvent(QEvent::KeyPress,Qt::Key_..., Qt::NoModifier);
QWidget* pWidget = qApp->activePopupWidget();
qApp->sendEvent(pWidget, &keyEvent);
… for other keys
But I always have to use the mouse to get an initial highlighted menu item. I tried a lot of things to get this highlighted item by program input.
With Qmenu::exec() I succeded to open a popup menu but could not get a highlighted item there, so the simulated inputs have no effect.
What am I doing wrong?