Qt-UI
Menus
← Window Title | ● | Settings →
Adding menu entries to a QMainWindow for the entries “Quit” and “About”:
QAction *quitAction = new QAction(tr("Q&uit"), this);
quitAction->setShortcuts(QKeySequence::Quit);
quitAction->setStatusTip(tr("Quit the application"));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(quitAction);
QAction *aboutAction = new QAction(tr("&About"), this);
aboutAction->setShortcut(tr("Ctrl+A"));
aboutAction->setStatusTip(tr("About this program"));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
quitAction->setShortcuts(QKeySequence::Quit);
quitAction->setStatusTip(tr("Quit the application"));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(quitAction);
QAction *aboutAction = new QAction(tr("&About"), this);
aboutAction->setShortcut(tr("Ctrl+A"));
aboutAction->setStatusTip(tr("About this program"));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
Selection of the Quit item of the file menu invokes the close() slot.
Selection of the About item of the help menu invokes the about() slot:
private slots:
void about()
{
QMessageBox::about(this, tr("About this program"),
tr("just an example"));
}
void about()
{
QMessageBox::about(this, tr("About this program"),
tr("just an example"));
}
← Window Title | ● | Settings →