How to highlight a menu item by program input
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:
Code:
QWidget* pWidget
= qApp
->activeWindow
()->focusWidget
();
qApp->sendEvent(pWidget, &keyEvent);
… for tab input or:
Code:
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?
Re: How to highlight a menu item by program input
Have you tried to send the KeyRelease event, after sending the KeyPress? For example I used this when I've tried to highlight my QMenu like it's going in Windows:
Code:
void MainWindow
::keyPressEvent(QKeyEvent* event
) {
if(event->key() == Qt::Key_Alt)
{
if(menuBar()->isHidden())
{
menuBar()->show();
qApp->sendEvent(menuBar(), &altPress);
qApp->sendEvent(menuBar(), &altRelease);
}
}
}