首页 > 其他 > 详细

Qt5学习:添加动作

时间:2015-10-31 12:43:46      阅读:227      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!