当前位置:网站首页>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
边栏推荐
- [app packaging error] to proceed, either fix the issues identified by lint, or modify your build script as follow
- H. 265 introduction to coding principles
- 【C语言】动态内存开辟的使用『malloc』
- How to improve the operation efficiency of intra city distribution
- How to use sqlcipher tool to decrypt encrypted database under Windows system
- Baidu app's continuous integration practice based on pipeline as code
- 一文读懂TDengine的窗口查询功能
- Tdengine can read and write through dataX, a data synchronization tool
- MySQL does not take effect in sorting string types
- Android privacy sandbox developer preview 3: privacy, security and personalized experience
猜你喜欢
From "chemist" to developer, from Oracle to tdengine, two important choices in my life
Tongweb set gzip
【技术直播】如何用 VSCode 从 0 到 1 改写 TDengine 代码
Node red series (29): use slider and chart nodes to realize double broken line time series diagram
美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
[sourcetree configure SSH and use]
如何获取GC(垃圾回收器)的STW(暂停)时间?
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
TDengine ×英特尔边缘洞见软件包 加速传统行业的数字化转型
Tdengine connector goes online Google Data Studio app store
随机推荐
Understanding of smt32h7 series DMA and DMAMUX
搞数据库是不是越老越吃香?
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
Online chain offline integrated chain store e-commerce solution
Community group buying has triggered heated discussion. How does this model work?
Principle and performance analysis of lepton lossless compression
Apache dolphin scheduler system architecture design
A keepalived high availability accident made me learn it again
The comparison of every() and some() in JS uses a power storage plan
【数组的中的某个属性的监听】
[object array A and object array B take out different elements of ID and assign them to the new array]
美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
[sorting of object array]
百度交易中台之钱包系统架构浅析
【js 根据对象数组中的属性进行排序】
Vs code problem: the length of long lines can be configured through "editor.maxtokenizationlinelength"
tongweb设置gzip
Kotlin Compose 与原生 嵌套使用
Single chip microcomputer principle and Interface Technology (esp8266/esp32) machine human draft
What about wechat mall? 5 tips to clear your mind