/**********************************
* 课程名 :QT编程
* 时 间 :2017年6月5日(周一)下午
* 工程名 :12 MainWindow
* 类 名 :mainWindow
* 内 容 :MainWindow
* 优快云 :Qt基础 10_MainWindow
**********************************/
一、MainWindow基础操作 之 添加资源文件
步骤一:新建资源文件
步骤二:添加前缀,将默认路径改为/img
步骤三:添加需要使用的图片文件
二、MainWindow基础操作 之 菜单条
自动版:
1、菜单及菜单项:在ui界面直接输入即可
2、图标
手动版:在构造函数中
1、菜单及菜单项:
QMenu *pm = new QMenu("手动设计菜单1");
pm->addAction(icon,"手动菜单项1");
this->menuBar()->addMenu(pm);
2、图标
相对路径方式,用文件夹中的icon
QIcon icon("D:/QT/icon1.jpg");
用资源文件 —— 格式:”:/前缀/文件相对于资源的路径/文件名”
QIcon icon(":/img/icon1.jpg");
3、添加功能
QAction *qa = new QAction(icon,"手动菜单项2,关闭",0);
pm->addAction(qa);
connect(qa,SIGNAL(triggered()),this,SLOT(close()));
三、MainWindow基础操作 之 工具条ToolBar
**自动版:**ctrl + 拖拽菜单项
手动版:
//定义手动菜单项
QAction *qa = new QAction(icon,"手动菜单项2,关闭",0);
//添加手动菜单项到工具栏
ui->mainToolBar->addAction(qa);
//添加新工具条
QToolBar *toolbar = new QToolBar("手写新工具条",this);
//将菜单项qa加入其中
this->addAction(qa);
//使其在右方
addToolBar(Qt::RightToolBarArea , toolbar);
四、MainWindow基础操作 之 状态栏statusBar
//显示指定时间的指定信息
ui->statusBar->showMessage("显示给定的Message5秒",5000);
//显示信息
QLabel *label = new QLabel("我是Label");
ui->statusBar->addWidget(label);
四、MainWindow基础操作 之 中心窗QLineEdit
QLineEdit *lineEdit = new QLineEdit("QLineEdit");
this->setCentralWidget(lineEdit);
源代码:download.youkuaiyun.com/download/c_estbon/9867033