当前位置:网站首页>写一个纯手写的qt的hello world
写一个纯手写的qt的hello world
2022-07-07 23:28:00 【bin elf】


实现效果:空项目


之后在项目文件中添加文件

实现了窗口和按钮控件的编写
#include <QApplication>
#include <QWidget> //引用头文件 窗口文件基类
#include <QPushButton> //按钮的控件
int main(int argc, char *argv[])
{
//有且只有一个应用程序类的对象---即使有很多个窗口
QApplication a(argc, argv);
//创建空白窗口
QWidget w;
w.setWindowTitle("给杨的窗口");//设置标题
//显示
w.show();
//创建按钮
QPushButton b;
b.setText("杨的专属按钮");//给按钮设施内容
b.show();//给空间认为显示
/*如果不指定父对象 对象和对象(窗口和窗口)没有关系,是独立的
*a指定b为它的父对象 相当于a在b上(子在父上面)
*所以本案例需要指定窗口是父对象 按钮是子对象 有两种方式
* 1)setParent
* 2)构造函数传参
*指定父对象的好处,只需要父对象显示 上面那的子对象自动显示*/
return a.exec();
}
是两个窗口

实现一个窗口显示
#include <QApplication>
#include <QWidget> //引用头文件 窗口文件基类
#include <QPushButton> //按钮的控件
int main(int argc, char *argv[])
{
//有且只有一个应用程序类的对象---即使有很多个窗口
QApplication a(argc, argv);
//创建空白窗口
QWidget w;
w.setWindowTitle("给的窗口");//设置标题
#include <QApplication>
#include <QWidget> //引用头文件 窗口文件基类
#include <QPushButton> //按钮的控件
int main(int argc, char *argv[])
{
//有且只有一个应用程序类的对象---即使有很多个窗口
QApplication a(argc, argv);
//创建空白窗口
QWidget w;
w.setWindowTitle("给杨妹妹的窗口");//设置标题
//创建按钮1
QPushButton b;
b.setText("杨的专属按钮");//给按钮设施内容
b.setParent(&w); //指定夫对象 此时显示在左上角 显示效果不好
//更改效果
b.move(100,100);//移动的是像素点
//创建按钮2
QPushButton b1(&w); //构造函数传参 指定父对象
b1.setText("abc");//给按钮设施内容
w.show();//给空间认为显示
/*如果不指定父对象 对象和对象(窗口和窗口)没有关系,是独立的
*a指定b为它的父对象 相当于a在b上(子在父上面)
*所以本案例需要指定窗口是父对象 按钮是子对象 有两种方式
* 1)setParent
* 2)构造函数传参
*指定父对象的好处,只需要父对象显示 上面那的子对象自动显示*/
return a.exec();
}
//创建按钮1
QPushButton b;
b.setText("杨的专属按钮");//给按钮设施内容
b.setParent(&w); //指定夫对象 此时显示在左上角 显示效果不好
//更改效果
b.move(100,100);//移动的是像素点
//创建按钮2
QPushButton b1(&w); //构造函数传参 指定父对象
b1.setText("abc");//给按钮设施内容
w.show();//给空间认为显示
/*如果不指定父对象 对象和对象(窗口和窗口)没有关系,是独立的
*a指定b为它的父对象 相当于a在b上(子在父上面)
*所以本案例需要指定窗口是父对象 按钮是子对象 有两种方式
* 1)setParent
* 2)构造函数传参
*指定父对象的好处,只需要父对象显示 上面那的子对象自动显示*/
return a.exec();
}

边栏推荐
- String usage in C #
- EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
- Ag9311maq design 100W USB type C docking station data | ag9311maq is used for 100W USB type C to HDMI with PD fast charging +u3+sd/cf docking station scheme description
- Matlab code on error analysis (MAE, MAPE, RMSE)
- The solution of frame dropping problem in gnuradio OFDM operation
- redis的持久化方式-RDB和AOF 两种持久化机制
- AttributeError: ‘str‘ object has no attribute ‘strftime‘
- 5. Discrete control and continuous control
- Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative
- 小金额炒股,在手机上开户安全吗?
猜你喜欢

The solution of frame dropping problem in gnuradio OFDM operation

LeetCode 练习——剑指 Offer 36. 二叉搜索树与双向链表

2022 refrigeration and air conditioning equipment operation examination questions and refrigeration and air conditioning equipment operation examination skills

How to write mark down on vscode

4、策略學習

The difference between distribution function and probability density function of random variables

Chapter VIII integrated learning

The Ministry of housing and urban rural development officially issued the technical standard for urban information model (CIM) basic platform, which will be implemented from June 1

Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design

Chapter 7 Bayesian classifier
随机推荐
5、离散控制与连续控制
Ag9311maq design 100W USB type C docking station data | ag9311maq is used for 100W USB type C to HDMI with PD fast charging +u3+sd/cf docking station scheme description
2021 Shanghai safety officer C certificate examination registration and analysis of Shanghai safety officer C certificate search
Chapter 16 intensive learning
Complete model verification (test, demo) routine
Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
Continued from the previous design
Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
Frrouting BGP protocol learning
2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
High quality USB sound card / audio chip sss1700 | sss1700 design 96 kHz 24 bit sampling rate USB headset microphone scheme | sss1700 Chinese design scheme explanation
Kaptcha generates verification code on Web page
Vs code configuration latex environment nanny level configuration tutorial (dual system)
How to write mark down on vscode
Using GPU to train network model
npm 内部拆分模块
A speed Limited large file transmission tool for every major network disk
4. Apprentissage stratégique
Vscode is added to the right-click function menu
5、離散控制與連續控制