当前位置:网站首页>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
边栏推荐
- LeetCode 556. Next bigger element III
- [200 opencv routines] 219 Add digital watermark (blind watermark)
- On July 2, I invite you to TD Hero online press conference
- Tutorial on building a framework for middle office business system
- What should we pay attention to when developing B2C websites?
- 【数组的中的某个属性的监听】
- Go 语言使用 MySQL 的常见故障分析和应对方法
- [object array A and object array B take out different elements of ID and assign them to the new array]
- [hungry dynamic table]
- 揭秘百度智能测试在测试自动执行领域实践
猜你喜欢
解决idea调试过程中liquibase – Waiting for changelog lock….导致数据库死锁问题
【OpenCV 例程200篇】219. 添加数字水印(盲水印)
单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
Baidu app's continuous integration practice based on pipeline as code
Apache DolphinScheduler 入门(一篇就够了)
Apache DolphinScheduler 系统架构设计
Windows uses commands to run kotlin
cent7安装Oracle数据库报错
Online chain offline integrated chain store e-commerce solution
LeetCode 556. Next bigger element III
随机推荐
Common fault analysis and Countermeasures of using MySQL in go language
Online chain offline integrated chain store e-commerce solution
Tdengine offline upgrade process
MySQL installation configuration and creation of databases and tables
Community group buying has triggered heated discussion. How does this model work?
Wechat applet obtains household area information
Lepton 无损压缩原理及性能分析
What about wechat mall? 5 tips to clear your mind
Solve the problem of no all pattern found during Navicat activation and registration
Unity skframework framework (XXIII), minimap small map tool
SQL learning alter add new field
Understanding of smt32h7 series DMA and DMAMUX
oracle 多行数据合并成一行数据
First understanding of structure
【C语言】动态内存开辟的使用『malloc』
[two objects merged into one object]
[hungry dynamic table]
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
Tongweb set gzip
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...