当前位置:网站首页>写一个纯手写的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();
}
边栏推荐
- Gnuradio3.9.4 create OOT module instances
- Know how to get the traffic password
- For the first time in China, three Tsinghua Yaoban undergraduates won the stoc best student thesis award
- How to write mark down on vscode
- Study notes of single chip microcomputer and embedded system
- Application of state mode in JSF source code
- Kaptcha generates verification code on Web page
- The beauty of Mathematics -- the principle of fine Fourier transform
- How to get the first and last days of a given month
- Introduction to the types and repair methods of chip Eco
猜你喜欢
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data
2022 free test questions of fusion welding and thermal cutting and summary of fusion welding and thermal cutting examination
3. MNIST dataset classification
Chapter VIII integrated learning
解决报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
3、多智能体强化学习
Application of state mode in JSF source code
Cs5261type-c to HDMI alternative ag9310 | ag9310 alternative
Kuntai ch7511b scheme design | ch7511b design EDP to LVDS data | pin to pin replaces ch7511b circuit design
Running OFDM in gnuradio_ RX error: gr:: Log: info: packet_ headerparser_ b0 - Detected an invalid packet at item ××
随机推荐
The examination contents of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge) in 2021 and the free examination questions of the third batch of Guangdong Prov
General configuration toolbox
11. Recurrent neural network RNN
2021-04-12 - new features lambda expression and function functional interface programming
5. Over fitting, dropout, regularization
10. CNN applied to handwritten digit recognition
Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
Application of state mode in JSF source code
ROS 问题(topic types do not match、topic datatype/md5sum not match、msg xxx have changed. rerun cmake)
Arm bare metal
Ag9310 same function alternative | cs5261 replaces ag9310type-c to HDMI single switch screen alternative | low BOM replaces ag9310 design
General configuration title
Connect to the previous chapter of the circuit to improve the material draft
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
Use "recombined netlist" to automatically activate eco "APR netlist"
Kafka-connect将Kafka数据同步到Mysql
redis的持久化方式-RDB和AOF 两种持久化机制
Introduction to the types and repair methods of chip Eco
Guojingxin center "APEC education +" Shanghai Jiaotong University Japan Cooperation Center x Fudan philosophy class "Zhe Yi" 2022 New Year greetings
break net