Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The absolute and relative layout of the form in pyqt5 and the required components or controls

Shulou Source: shulou.com Published: 2022-06-02 04:53:27 09月30日 Update

This article mainly explains the "absolute and relative layout of forms in pyqt5 as well as the required components or controls". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to study and learn "the absolute and relative layout of forms in pyqt5 as well as the required components or controls".

I. relative layout and absolute layout

Relative layout

The controls in the layout can change as the form changes.

The distance between the controls in the layout can be adjusted proportionally.

The difference between absolute layout and relative layout

1. The absolute layout is to load the control directly into the location of the form. Generally speaking, the move function is directly used to move to the specified location and remain unchanged.

two。 The relative layout is to place the control in the box layout. Generally, you also need to add a box layout QHboxlayout (horizontal) Qvboxlayout (vertical), grid layout (Qgridboxlayout)

2. Components or controls to be used

QLineEdit control

Single-line input box: only one line of text edit box can be entered.

QHBoxlayout horizontal box layout

All the controls can only be arranged horizontally and will be arranged one by one without overlap. Vertically centered by default.

Memory style: if you look at the horizontal line in H, you can think of it as a horizontal layout.

III. Layout

Use the similar spring function: just use the addstretch method of the box layout directly.

The addstretch function can also split the white space proportionally.

Use format:

Layout box. Addstretch (spring scale)

Spring scale: refers to the specified proportional division in a blank layout in the form.

Vertical layout can be carried out by using QVBoxlayout, and when the idea of vertical layout is understood, the layout can be more flexible by adding springs appropriately.

IV. Summary and emphasis

1. Master the difference between relative layout and absolute layout.

two。 Master the horizontal box layout and vertical box layout in the relative layout.

3. Master the relationship between the proportional layout of controls in the box layout.

The knowledge source code of this section:

Import sysfrom PyQt5.QtWidgets import QApplication,QWidget,QVBoxLayout,QHBoxLayout,QGridLayout,QLineEdit,QLabel,QPushButton

Class MyljyClass (QWidget): def _ init__ (self): super (). _ init__ () self.initUI ()

Def initUI (self): self.setWindowTitle ("Liu Jinyu programming") self.setGeometry (app.desktop (). Width () / 2-self.width () / 2mai 50400300)

LblCode=QLabel ("CAPTCHA", self) leCode=QLineEdit (self) btnCode=QPushButton ("verification", self)

# leCode.move (40) # btnCode.move (190)

# hlayout=QHBoxLayout (self) # hlayout.addWidget (lblCode) # hlayout.addWidget (leCode) # hlayout.addWidget (btnCode)

Vlayout=QVBoxLayout (self) # vlayout.addLayout (hlayout) vlayout.addWidget (lblCode) vlayout.addStretch (1) vlayout.addWidget (leCode) vlayout.addStretch (1) vlayout.addWidget (btnCode) vlayout.addStretch (2)

Self.show ()

If _ _ name__== "_ _ main__": app=QApplication (sys.argv) mljy=MyljyClass () app.exec_ () Thank you for your reading. The above is the content of "absolute and relative layout of forms and required components or controls in pyqt5". After the study of this article, I believe you have a deeper understanding of the absolute and relative layout of forms in pyqt5 as well as the required components or controls. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Layout control form scale component horizontal spring situation direction learning validation location content function that is knowledge blank change input different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn MariaDB Docker Microsoft