Qt5-control-QMenu, QMenuBar-menu bar details-menu hotkey-menu verification function, qt5-qmenu
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QMenu>#include <QMenuBar>#include <QStatusBar>class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); QMenu* menu[10]; QAction* act[10]; QMenuBar* menuBar ; QStatusBar* status ;public slots: void trigerMenu(QAction* act);};#endif // MAINWINDOW_H
# Include "mainwindow. h "# include <Qt >#include <QtDebug> MainWindow: MainWindow (QWidget * parent): QMainWindow (parent) {this-> resize (400,300 ); this-> centralWidget (); status = new QStatusBar (this); menu [0] = new QMenu ("file "); menu [0]-> addAction ("edit"); menu [0]-> addAction ("View"); menu [0]-> addAction ("tool "); act [0] = new QAction ("new", this); act [0]-> setShortcut (Qt: CTRL | Qt: Key_A ); act [0]-> setStatusTip ("This Is "); Act [1] = new QAction (" open ", this); act [1]-> setCheckable (true ); menu [1] = new QMenu ("save"); menu [1]-> addAction (act [0]); menu [1]-> addAction (act [1]); menu [2] = new QMenu ("print "); menu [2]-> addAction ("Print Settings"); menu [2]-> addMenu (menu [1]); menuBar = new QMenuBar (this ); menuBar-> addMenu (menu [0]); menuBar-> addMenu (menu [2]); menuBar-> setGeometry (0, 0, this-> width (), 30 ); connect (menuBar, SIGNAL (triggered (QAct Ion *), this, SLOT (trigerMenu (QAction *);} MainWindow ::~ MainWindow () {} void MainWindow: trigerMenu (QAction * act) {if (act-> text () = "new") {qDebug () <"the new menu is pressed ";}}
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}