码迷,mamicode.com
首页 > 其他好文 > 详细

Qt5学习:添加动作

时间:2015-10-31 12:46:12      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

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"));
}

 

Qt5学习:添加动作

标签:

原文地址:http://www.cnblogs.com/somebod-Y/p/4925256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!