QT每日一练day11:QMainWindow
一.第一阶段
运行结果(GIF动图):
day11.pro
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \mainwindow.cppHEADERS += \mainwindow.h# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();
public slots:void saveSLot();
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include<QMenuBar>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{this->resize(640,480);QMenuBar* menuBar=this->menuBar();QMenu* fileMenu = new QMenu("文件(&F)",menuBar);//这里设置Alt+F是该按钮的快捷键fileMenu->addAction("default")->setCheckable(true);//是否可对勾点选fileMenu->addSeparator();//添加一个分隔线fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy.png"),"打开");fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy.png"),"关闭",this,SLOT(close()));fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy.png"),"保存",this,SLOT(saveSlot()),QKeySequence("Ctrl+s"));fileMenu->addMenu("子菜单")->addAction("default");menuBar->addMenu(fileMenu);menuBar->addMenu("帮助(&H)");
}void MainWindow::saveSLot()
{qDebug()<<__FUNCTION__<<endl;
}MainWindow::~MainWindow()
{}
main.cpp
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}
二.第二阶段
运行结果(GIF动图):
day11.pro
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \mainwindow.cppHEADERS += \mainwindow.h# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();
private:void initMenuBar();void initToolBar();void initDock();
public slots:void saveSLot();
private:QAction* _open;QAction* _close;QAction* _save;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include"mainwindow.h"
#include<QMenuBar>
#include<QToolBar>
#include<QDebug>
#include<QStatusBar>
#include<QTextEdit>
#include<QDockWidget>
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{QTextEdit* edit=new QTextEdit(this);this->resize(640,480);this->initMenuBar();this->initToolBar();this->initDock();this->statusBar()->showMessage("就绪",5000);//状态栏,显示时间(可选)this->setCentralWidget(edit);}void MainWindow::initToolBar()
{QToolBar* toolBar = this->addToolBar("toolBar");toolBar->addAction(_open);toolBar->addAction(_close);toolBar->addAction(_save);
}
void MainWindow::initDock()
{QTextEdit* edit=new QTextEdit(this);QDockWidget* dock=new QDockWidget(this);this->addDockWidget(Qt::LeftDockWidgetArea,dock);dock->setWidget(edit);
}void MainWindow::initMenuBar()
{this->resize(640,480);QMenuBar* menuBar=this->menuBar();QMenu* fileMenu = new QMenu("文件(&F)",menuBar);//这里设置Alt+F是该按钮的快捷键fileMenu->addAction("default")->setCheckable(true);//是否可对勾点选fileMenu->addSeparator();//添加一个分隔线_open=fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy1.png"),"打开");_close=fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy2.jpg"),"关闭",this,SLOT(close()));_save=fileMenu->addAction(QIcon("C:/Users/xiaowen/Pictures/boy3.jpg"),"保存",this,SLOT(saveSlot()),QKeySequence("Ctrl+s"));fileMenu->addMenu("子菜单")->addAction("default");menuBar->addMenu(fileMenu);menuBar->addMenu("帮助(&H)");
}
void MainWindow::saveSLot()
{qDebug()<<__FUNCTION__<<endl;
}MainWindow::~MainWindow()
{}
main.cpp
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}
三.附:概念
QT每日一练day11:QMainWindow相关推荐
- QT每日一练day4:ubuntu中使用QT
(本文主要是为了说明QT的跨平台特性) 一.安装QT sudo apt-get install qt5-default qtcreator cmake 二.打开QT 可以点击图标或命令行方式: 三 ...
- QT每日一练day1:第一个程序
参考博文:Qt常见类.窗口类继承关系树图 QT每日一练(1):第一个程序 最终效果(GIF动图): step1: step2: step3: step4: step5: step6: step7: s ...
- QT每日一练day19:设计一个记事本
一.第一阶段 widget.h widget.cpp 上述程序直接运行: 二.第二阶段 widget.cpp 运行 三.第三阶段 xiaowen_EDIT.pro QT += core guigrea ...
- QT每日一练day29:QT中的多线程探究
一.未使用多线程,则w0先运行完后,w1才开始运行 运行结果(GIF动图): main.cpp xiaowen_QT_day29.pro QT+=widgets SOURCES += \main.cp ...
- QT每日一练day27:绘制不规则窗体
注:本文本来应该是以一个不规则的图片作为历程的,,忘记了!!!! 一.第一阶段:隐藏窗体框架 运行结果(GIF动图): widget.cpp 二.第二阶段:将窗口设置为透明 运行结果(GIF动 ...
- QT每日一练day26:绘制图片
一.第一阶段 发现上述图片没有显示全!!!!! 二.第二阶段 设置宽高比,平滑转换 运行结果(GIF动图): 发现上述图片在数次缩放后会产生失真!!!!! 三.第三阶段 为了避免图像缩放过程中产生失真 ...
- QT每日一练day25:触发绘画事件
运行结果(GIF动图): widget.cpp 附代码: xiaowen_QT_day25.pro QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT ...
- QT每日一练day24:绘画事件
一.第一阶段 设置线条粗细 二.第二阶段:设置笔的样式 如:虚线 三.第三阶段:绘制矩形 四.第四阶段:设置颜色 轮廓颜色 笔刷颜色 笔刷样式 五.第五阶段:绘制其他形状图像和文字 六.第六阶段:图像 ...
- QT每日一练day23:鼠标进入与离开事件
运行结果(GIF动图): xiaowen_QT_day23.pro QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFI ...
最新文章
- IIS服务器下做301永久重定向设置方法[图解]
- 什么是关键字驱动框架(自动化测试)
- iOS 够逼格的注释总结
- leetcode 67 Add Binary
- php案例纠错,PHP编程纠错指南
- 纽交所发言人就“GME事件”表态:采用先进技术监督市场
- 仅让演讲者看到备注信息
- 奇安信代码安全实验室帮助微软修复两个“重要”漏洞,获官方致谢
- 【小墩墩学Android】开发环境(一)
- Thinkphp5 谷歌验证
- ai将会怎样影响计算机的发展,AI再升级!人工智能会对我们的未来产生怎样的影响?...
- 中国首个“芯片大学”即将落地;生成对抗网络(GAN)的数学原理全解
- Elasticsearch之高亮进阶-高性能高亮器, 让Elasticsearch飞一会儿
- GlusterFS探究(一): dht,afr,fuse, mgmt 层 几个问题总结
- HTTP3 (QUIC) 协议
- 准备离职了,公司决定加薪留住我,是去是留?
- 利用URL查看网页源代码
- 论文分享 Deep Distance Transform for Tubular Structure Segmentation in CT Scans
- python学习笔记一——鸭子模型
- mac电脑磁盘满了怎么办?mac电脑磁盘空间不足怎么办
热门文章
- 玩转springboot2.x之搭建Thymeleaf官方示例程序
- Execution failed for task ':app:mergeDebugResources
- 基于JAVA+SpringBoot+Mybatis+MYSQL的贷款审批系统
- 【JAVA面试】java面试题整理(4)
- HTC Vive 叠影器无法创建设备
- Android 异步加载神器Loader全解析
- A. 面向对象思想介绍
- begin.lydsy 入门OJ题库:1104:那些N位数
- jQuery-处理元素内容、表单元素
- [特约· Keso ·东拉西扯] 我眼中的乔布斯