当前位置:网站首页>写一个纯手写的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();
}

边栏推荐
- LeetCode 练习——剑指 Offer 36. 二叉搜索树与双向链表
- 2021 tea master (primary) examination materials and tea master (primary) simulation test questions
- npm 内部拆分模块
- 2021-03-14 - play with generics
- USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
- Application of state mode in JSF source code
- Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
- Common fault analysis and Countermeasures of using MySQL in go language
- Guojingxin center "friendship and righteousness" - the meta universe based on friendship and friendship, and the parallel of "honguniverse"
- Know how to get the traffic password
猜你喜欢

2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions

Solve the error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.

General configuration title

Transportation, new infrastructure and smart highway

Ag7120 and ag7220 explain the driving scheme of HDMI signal extension amplifier | ag7120 and ag7220 design HDMI signal extension amplifier circuit reference

Gnuradio transmits video and displays it in real time using VLC

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

Chapter 16 intensive learning

Chapter XI feature selection

Measure the voltage with analog input (taking Arduino as an example, the range is about 1KV)
随机推荐
Chapter IV decision tree
Macro definition and multiple parameters
NPM Internal Split module
2021 welder (primary) examination skills and welder (primary) operation examination question bank
Talk about smart Park
[loss function] entropy / relative entropy / cross entropy
common commands
3. Multi agent reinforcement learning
EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
Gnuradio3.9.4 create OOT module instances
Understanding of expectation, variance, covariance and correlation coefficient
STM32GPIO口的工作原理
2022 safety officer-a certificate free examination questions and safety officer-a certificate mock examination
Redis 主从复制
10. CNN applied to handwritten digit recognition
Apt get error
2021-03-14 - play with generics
11. Recurrent neural network RNN
Chapter 7 Bayesian classifier
break algorithm---刷题map