Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report