PDA

View Full Version : To set keyboard focus on QMenu item pragrammatically



maniac@kernel
12th April 2013, 10:14
i am developing a Qt based GUI software.Whenever this software starts up, focus is set to the mainwindow.And there is no way to access the menu bar unless you are setting the focus to the menu by clicking the mouse on it.But my software requirements restricted the use of the mouse(only keyboard will be used as the medium of interaction with users);plz advise how
can i do that

Here is my existing code.

main.cpp



#include <QApplication>
#include <QMainWindow>
#include <QMenuBar>
int main(int argc, char **argv)
{
QApplication app(argc, argv);

QMainWindow *window = new QMainWindow();


window->setWindowTitle(QString::fromUtf8("Test:QMenu"));
window->resize(336, 227);



QAction *newAct = new QAction("&New",window);
QAction *openAct = new QAction("&Open",window);
QAction *saveAct = new QAction("&Save",window);

QMenu *fileMenu;

fileMenu = window->menuBar()->addMenu("&File");
fileMenu->addAction(newAct);
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);


window->show();

fileMenu->popup(QPoint(10,10));



return app.exec();
}

wysota
16th April 2013, 20:30
Set keyboard accelerators on your menus.

Urthas
17th April 2013, 06:58
You might consider looking into tab order?