当前位置:网站首页>Write a pure handwritten QT Hello World
Write a pure handwritten QT Hello World
2022-07-08 01:28:00 【bin elf】


Realization effect : Empty item


Then add the file in the project file 

Realize the compilation of window and button controls
#include <QApplication>
#include <QWidget> // Reference header file Window file base class
#include <QPushButton> // Button controls
int main(int argc, char *argv[])
{
// Objects with and only one application class --- Even if there are many windows
QApplication a(argc, argv);
// Create a blank window
QWidget w;
w.setWindowTitle(" Window for Yang ");// Set title
// Show
w.show();
// Create button
QPushButton b;
b.setText(" Yang's exclusive button ");// Give the button facility content
b.show();// Give space that shows
/* If you do not specify a parent object Objects and objects ( Windows and windows ) It doesn't matter. , It's independent
*a Appoint b For its parent amount to a stay b On ( The son is above the father )
* So this case needs to specify that the window is the parent object Buttons are sub objects There are two ways
* 1)setParent
* 2) Constructor arguments
* Benefits of specifying a parent , You just need the parent object to display The sub objects above are automatically displayed */
return a.exec();
}
There are two windows

Realize a window display
#include <QApplication>
#include <QWidget> // Reference header file Window file base class
#include <QPushButton> // Button controls
int main(int argc, char *argv[])
{
// Objects with and only one application class --- Even if there are many windows
QApplication a(argc, argv);
// Create a blank window
QWidget w;
w.setWindowTitle(" Window for ");// Set title
#include <QApplication>
#include <QWidget> // Reference header file Window file base class
#include <QPushButton> // Button controls
int main(int argc, char *argv[])
{
// Objects with and only one application class --- Even if there are many windows
QApplication a(argc, argv);
// Create a blank window
QWidget w;
w.setWindowTitle(" Window for younger sister Yang ");// Set title
// Create button 1
QPushButton b;
b.setText(" Yang's exclusive button ");// Give the button facility content
b.setParent(&w); // Specify the husband object It is displayed in the upper left corner The display effect is not good
// Change effect
b.move(100,100);// Moving pixels
// Create button 2
QPushButton b1(&w); // Constructor arguments Specify the parent object
b1.setText("abc");// Give the button facility content
w.show();// Give space that shows
/* If you do not specify a parent object Objects and objects ( Windows and windows ) It doesn't matter. , It's independent
*a Appoint b For its parent amount to a stay b On ( The son is above the father )
* So this case needs to specify that the window is the parent object Buttons are sub objects There are two ways
* 1)setParent
* 2) Constructor arguments
* Benefits of specifying a parent , You just need the parent object to display The sub objects above are automatically displayed */
return a.exec();
}
// Create button 1
QPushButton b;
b.setText(" Yang's exclusive button ");// Give the button facility content
b.setParent(&w); // Specify the husband object It is displayed in the upper left corner The display effect is not good
// Change effect
b.move(100,100);// Moving pixels
// Create button 2
QPushButton b1(&w); // Constructor arguments Specify the parent object
b1.setText("abc");// Give the button facility content
w.show();// Give space that shows
/* If you do not specify a parent object Objects and objects ( Windows and windows ) It doesn't matter. , It's independent
*a Appoint b For its parent amount to a stay b On ( The son is above the father )
* So this case needs to specify that the window is the parent object Buttons are sub objects There are two ways
* 1)setParent
* 2) Constructor arguments
* Benefits of specifying a parent , You just need the parent object to display The sub objects above are automatically displayed */
return a.exec();
}

边栏推荐
- Codeforces Round #804 (Div. 2)
- Recommend a document management tool mendely Reference Manager
- Probability distribution
- Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method
- AttributeError: ‘str‘ object has no attribute ‘strftime‘
- npm 內部拆分模塊
- Generic configuration legend
- Gnuradio3.9.4 create OOT module instances
- Understanding of prior probability, posterior probability and Bayesian formula
- 2021 tea master (primary) examination materials and tea master (primary) simulation test questions
猜你喜欢

The beauty of Mathematics -- the principle of fine Fourier transform

Redis master-slave replication

Know how to get the traffic password

4、策略學習

Four digit nixie tube display multi digit timing

Talk about smart Park

2022 low voltage electrician examination content and low voltage electrician simulation examination question bank

Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data

Share a latex online editor | with latex common templates

Markdown learning (entry level)
随机推荐
Understanding of prior probability, posterior probability and Bayesian formula
Smart grid overview
Redis集群
USB type-C docking design | design USB type-C docking scheme | USB type-C docking circuit reference
Taiwan Xinchuang sss1700 latest Chinese specification | sss1700 latest Chinese specification | sss1700datasheet Chinese explanation
Kindle operation: transfer downloaded books and change book cover
Recommend a document management tool Zotero | with tutorials and learning paths
General configuration toolbox
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
Design method and application of ag9311maq and ag9311mcq in USB type-C docking station or converter
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
Getting started STM32 -- how to learn stm32
npm 内部拆分模块
Common effects of line chart
Continued from the previous design
Solve the error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
How to get the first and last days of a given month
USB type-C mobile phone projection scheme | USB type-C docking station scheme | TV / projector type-C converter scheme | ag9300ag9310ag9320
2022 chemical automation control instrument examination summary and chemical automation control instrument simulation examination questions
2022 new examination questions for crane driver (limited to bridge crane) and question bank for crane driver (limited to bridge crane) operation examination