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 centering and layout of pyqt5 forms and the use of library Qlabel

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

Share

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

This article introduces the knowledge of "the center and layout of pyqt5 forms and the usage of library Qlabel". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Second, the center of the form

1. By default, our form is centered on the screen by default.

two。 Manually adjust to the center of the screen

Get the object QDesktopWidget of the desktop control through the desktop () function

Get the resolution of the width of the screen through the width () function of the desktop object

For example, output desktop resolution:

Dk=app.desktop ()

Print (dk.width ())

Form schematic diagram

Horizontal center

Dk.width () / 2-mf1.width () / 2

Vertical center

Dk.height () / 2-mf1.height () / 2

Third, learn a new control

The use of label text controls requires us to use the class library Qlabel

Use format:

Variable object = QLabel (the text content of the label, the control in which the label is located)

Examples of use:

Lbl=QLabel ("programming creates cities", self)

Use of absolute layout:

Directly through the move to the location of a pixel

Features: very flexible

Weakness: cannot change with the form

IV. Summary and emphasis

1. The method of mastering the central layout of the form

two。 Master the method of using absolute layout and its advantages and disadvantages

The knowledge source code of this section:

Import sysfrom PyQt5.QtWidgets import QApplication,QWidget,QLabel

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

Def initUI (self): self.setWindowTitle ("Liu Jinyu programming") lbl=QLabel ("programming creates the City", self) self.resize (400300) self.move (50jing50) self.show ()

Def center (self): pass

If _ name__== "_ main__": app=QApplication (sys.argv) dk = app.desktop () # initialized form mf1=MyForm1 () mf1.move (dk.width () / 2-mf1.width () / 2, dk.height () / 2-mf1.height () / 2)

That's all for app.exec_ (), "pyqt5 form centering and layout and library Qlabel usage". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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