标签:
mainwindow.h如下:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); private: void open(); QAction *openAction; }; #endif // MAINWINDOW_H
mainwindow.cpp如下:
#include "mainwindow.h" #include <QAction> #include <QMenuBar> #include <QMessageBox> #include <QStatusBar> #include <QToolBar> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle(tr("Main Window")); this->openAction = new QAction(QIcon(":/images/doc-open"), tr("&Open..."), this); this->openAction->setShortcuts(QKeySequence::Open); this->openAction->setStatusTip(tr("Open an existing file")); connect(this->openAction, &QAction::triggered, this, &MainWindow::open); QMenu *file = this->menuBar()->addMenu(tr("&File")); file->addAction(openAction); QToolBar *toolBar = this->addToolBar(tr("&File")); toolBar->addAction(openAction); this->statusBar(); } MainWindow::~MainWindow() { } void MainWindow::open() { QMessageBox::information(this, tr("Information"), tr("Open")); }
标签:
原文地址:http://www.cnblogs.com/somebod-Y/p/4925256.html