QT 菜单程序
来源:互联网 发布:我的淘宝没有数据分析 编辑:程序博客网 时间:2024/05/22 06:27
MainWindow.h
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include<QMainWindow>#include<QMessageBox>class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow();private slots: void fExit(); void iInfo();private: void createMenus(); void createActions(); QAction *exit; QAction *info; QMenu *file; QMenu *about; QMessageBox *msgBox;};#endif // MAINWINDOW_H
MainWindow.cpp
#include<QtGui>#include"MainWindow.h"MainWindow::MainWindow(){ QWidget *widget=new QWidget; setCentralWidget(widget); QWidget *topfiller=new QWidget; topfiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QWidget *bottomFiller=new QWidget; bottomFiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); createActions(); createMenus(); QVBoxLayout *layout=new QVBoxLayout; layout->addWidget(topfiller); layout->addWidget(bottomFiller); widget->setLayout(layout); setWindowTitle(tr("Main Window")); resize(512,480);}void MainWindow::createActions(){ exit=new QAction(tr("Exit"),this); exit->setShortcut(QKeySequence::Close); connect(exit,SIGNAL(triggered()),this,SLOT(fExit())); info =new QAction(tr("Info"),this); info->setShortcut(QKeySequence::HelpContents); connect(info,SIGNAL(triggered()),this,SLOT(iInfo()));}void MainWindow::createMenus(){ file=menuBar()->addMenu(tr("File")); file->addAction(exit); about=menuBar()->addMenu(tr("About")); about->addAction(info);}void MainWindow::fExit(){ MainWindow::close();}void MainWindow::iInfo(){ msgBox=new QMessageBox; msgBox->setText(tr("hello world")); msgBox->setIcon(QMessageBox::Question); msgBox->setStandardButtons(QMessageBox::Ok); msgBox->exec();}
Main.cpp
#include<QApplication>#include"MainWindow.h"int main(int argc,char* argv[]){ QApplication app(argc,argv); MainWindow wnd; wnd.show(); app.exec();}
运行效果:
- QT 菜单程序
- Qt程序创建菜单
- Qt程序创建菜单
- 为QT程序编写右键菜单
- 为QT程序编写右键菜单
- 让Qt程序显示中文右键菜单
- Qt菜单、文件、信号与槽最简单程序
- Qt:QT右键菜单
- Qt:QT右键菜单
- qt 菜单例程注释
- QT右键菜单
- qt 添加右键菜单
- QT右键菜单
- QT右键菜单(转)
- QT 鼠标右键菜单
- qt的弹出式菜单
- Qt右键菜单
- qt 右键菜单
- C++中的const关键字
- Struts2中的ModelDriven机制
- java匿名内部类
- 网购小心钓鱼网站
- one day (安妮·海瑟薇,吉姆·斯特吉斯)
- QT 菜单程序
- 职业生涯规划 公开课,听课笔记
- VIM粘贴缩进问题
- ARM指令STMFD和LDMFD
- android 设置系统屏幕亮度
- Man Left in the Middle Attack Method中间人攻击
- 适配器模式
- 中关村-DIY笔记本之散热底座导购
- Java泛型简明教程