当前位置:网站首页>Six simple cases of QT
Six simple cases of QT
2022-07-05 09:56:00 【Sunqk5665】
Catalog
One 、 Login screen
The base class is Dialog, Add a as the main interface MainWindow class
Directory structure :
pro Add the following code to the file to add the icon :
RC_ICONS = myico.ico
Landing interface design :
dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
#include "QMessageBox"//
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_2_clicked()//
{
close();
}
void Dialog::on_pushButton_clicked()//
{
if(ui->lineEdit->text().trimmed()=="abc123"&&ui->lineEdit_2->text().trimmed()=="123"){
accept();
}
else {
QMessageBox::question(this,tr(" Warning "),tr(" Wrong user name or password !!!"),QMessageBox::Yes,QMessageBox::No);
}
}
main.cpp
#include "dialog.h"
#include <QApplication>
#include"mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
MainWindow w1;//
if(w.exec()==QDialog::Accepted){
//
w1.show();//
}//
return a.exec();
}
mainwindow.cpp Don't change
Two 、 Menus and toolbars
Create a new one MainWindow, Double click to add menu name and submenu name , Carriage return application , Add English half angle character ==(&F)== You can use shortcut keys at runtime alt+F Trigger .
Add Icon of submenu :
Double click on the action
Of course, this is just a simple addition to the menu , Not endowed with function , You can also add some functions , For example, you can add a text copy function , Here you can go to my other article Qt stay MainWndow Realize the text copy function in the menu bar in
Be careful : Don't add image resources directly to the project path , It can be placed outside the upper level directory or the upper level directory , or ,, Hey ,, You can't load it ...
3、 ... and 、 Keyboard events
turn ~:https://blog.csdn.net/weixin_43624626/article/details/115493337
Four 、 Mouse events ( Roller …)
turn ~:https://blog.csdn.net/weixin_43624626/article/details/115493337
5、 ... and 、 Event filtering ( Mouse button )
turn ~:https://blog.csdn.net/weixin_43624626/article/details/115700771
6、 ... and 、 Set irregular form ( transparency )
1、 Create a new one Qt Widget application , Base class selection QWidget, The class name can remain the default .
2、 Add a background transparent png picture
3、 stay widget.cpp Add header file to
#include<QPixmap>
#include<QBitmap>
#include<QPainter>
4、 Get into widget.h In the source file , Declare two event handlers
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *);
5、 Then add the following code to the constructor , Used to load pictures 、 Set the window size and call setMask() Function to set the shield for the window .
QPixmap pix;
pix.load("../buguize/touming.png");
resize(pix.size());
setMask(pix.mask());
6、 Add two more event handlers , A drawing for pictures , The other one is used to click the image with the mouse to close the window .
void Widget::paintEvent(QPaintEvent *){
QPainter painter(this);
painter.drawPixmap(0,0,QPixmap("../buguize/touming.png"));
}
void Widget::mousePressEvent(QMouseEvent *){
close();
}
7、 Build and run it to see the effect
边栏推荐
- Gradientdrawable get a single color
- Resolve the horizontal (vertical) sliding conflict between viewpager and WebView
- 一文读懂TDengine的窗口查询功能
- Go 语言使用 MySQL 的常见故障分析和应对方法
- 【sourceTree配置SSH及使用】
- The comparison of every() and some() in JS uses a power storage plan
- [technical live broadcast] how to rewrite tdengine code from 0 to 1 with vscode
- 观测云与 TDengine 达成深度合作,优化企业上云体验
- How to improve the operation efficiency of intra city distribution
- 揭秘百度智能测试在测试自动执行领域实践
猜你喜欢
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
一文读懂TDengine的窗口查询功能
oracle 多行数据合并成一行数据
LeetCode 496. Next larger element I
The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
百度交易中台之钱包系统架构浅析
Community group buying exploded overnight. How should this new model of e-commerce operate?
Go 语言使用 MySQL 的常见故障分析和应对方法
Tdengine already supports the industrial Intel edge insight package
Lepton 无损压缩原理及性能分析
随机推荐
Apache DolphinScheduler 入门(一篇就够了)
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
The most comprehensive promotion strategy: online and offline promotion methods of E-commerce mall
Flutter development: a way to solve the problem of blank space on the top of listview
Apache DolphinScheduler 系统架构设计
搞数据库是不是越老越吃香?
基于宽表的数据建模应用
【饿了么动态表格】
A keepalived high availability accident made me learn it again
Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
On July 2, I invite you to TD Hero online press conference
[technical live broadcast] how to rewrite tdengine code from 0 to 1 with vscode
H.265编码原理入门
Develop and implement movie recommendation applet based on wechat cloud
使用el-upload封装得组件怎么清空已上传附件
代码语言的魅力
从“化学家”到开发者,从甲骨文到TDengine,我人生的两次重要抉择
如何正确的评测视频画质
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
MySQL installation configuration and creation of databases and tables