[Qt] QPushButton button

[Qt] QPushButton button

Table of contents

[Qt] QPushButton button

1. Window creation (container for other components)

(1) Window header file

(2) Window source file

2. Create button

Use of QPushButton class

The process of creating a button


1. Window creation (container for other components)

Note: Components depend on the existence of windows, so when learning buttons, you first need to create windows, and subsequent buttons or other components all depend on this window, that is, they are all included in this window

(1) Window header file

(2) Window source file

2. Create button

Use of QPushButton class

Note: QPushBoutton is a button control, so it needs to depend on the existence of the window. The main function introduces the window and displays it. The creation and related settings of the window are in mywidget.cpp/h, so when creating controls such as buttons, create them in the .cpp file of the window

The process of creating a button

(1) Create QPushButton * btn = new QPushButton 
(2) Set the parent setParent(this) 
(3) Set the text setText("text") 
(4) Set the position move(width, height) 
(5) Re-specify the window size resize 
( 6) Set window title setWindowTitle 
(7) Set window fixed size setFixedSize

In the above code, a button is actually an object under the QPushButton class. If you just create an object, it cannot be displayed in the window, so we need to rely on a parent window, that is, specify a father and use the setParent function . If you want Set the text displayed on the button using setText, and move the button position using move

For the window, we can modify the title setWindowTitle of the window in the upper left corner, re-specify the window size: resize, or set a fixed window size setFixedSize;

Guess you like

Origin blog.csdn.net/m0_53415522/article/details/127669051