当前位置:网站首页>(7) Pyqt5 tutorial -- > > window properties and basic controls (continuous update)
(7) Pyqt5 tutorial -- > > window properties and basic controls (continuous update)
2022-06-25 12:37:00 【haoming Hu】
1. Form settings
| Set the form name | setWindowTitle(‘title’) |
|---|---|
| Set the form icon | self.setWindowIcon(‘image path’) |
| Change the size of the form | self.resize(height, wide) |
| Get the size of the form | self.size() |
| Get the width of the form | self.width() |
| Get the height of the form | self.height() |
| Do not stretch window size | self.setFixedSize(width,height) |
| Don't maximize | self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) |
| Get the starting coordinates of the window | self.pos() |
| Get the size and position of the window | self.frameGeometry() |
| Set window initialization position | self.setGeometry(x, y, width, height) |
| Set the window size | self.setFixedSize(width, height) |
2. Basic controls
1. Message box —>QMessageBox
Inheritance relationships :QtWidgets.QMessageBox
Message box type
| QMessageBox.information | Message box |
|---|---|
| QMessageBox.question | Question and answer box |
| QMessageBox.warning | Warning box |
| QMessageBox.critical | Error box |
| QMessageBox.about | About the box |
give an example :QMessageBox.information(QWidget, ‘Title’, 'Content‘, buttons)
QWidget: It's an interface parameter , It can be understood as a parent window
Title: The title of the message box
Content: The contents of the message box
buttons: The button in the message box ( Can be more )
Parametric button There are many kinds , As follows
- QMessageBox.Ok
- QMessageBox.Yes
- QMessageBox.No
- QMessageBox.Close
- QMessageBox.Cancel
- QMessage.Open
- QMessage.Save
There will be a return value after the message box runs , The return value is which button you choose , Here's a concrete example
choice=QtWidgets.QMessageBox.question(self,u'Notice!',u'Are you sure to exit?'
,QtWidgets.QMessageBox.Yes,QtWidgets.QMessageBox.No)
if choice==QtWidgets.QMessageBox.Yes:
print(" You chose the OK button ")
else:
print(" You chose the no button ")
Running effect :
2. Single line text box :QLineEdit
This is a single line of text input , Be similar to QQ Input box of login interface , You can set plaintext or ciphertext
Let's first introduce some common methods owned by this class
Some methods don't need to pass parameters , Some need
| setFont(combobox.currentFont()) | Set the font |
|---|---|
| setPlaceholderText() | Set the text box to display text |
| setMaxLength() | Set the maximum number of characters allowed in the text box |
| setReadOnly() | Set the text to read-only |
| setText() | Set the content of the text box |
| text() | Returns the contents of the text box |
| setDragEnable() | Sets whether the text box accepts dragging |
| selectAll() | Future generations |
| setFocus() | Get the focus |
self.setAlignment( Parameters ) Used to set the alignment of text
| Qt.AlignLeft | Align horizontally to the left |
|---|---|
| Qt.AlignRight | Horizontally right aligned |
| Qt.AlignCenter | Align horizontally and Center |
| Qt.AlignJustify | Adjust the spacing horizontally and align the ends |
| Qt.AlignTop | Vertical alignment up |
| Qt.AlignBottom | Align vertically down |
| Qt.AlignVCenter | Align vertically in the middle |
self.setEchoMode( Parameters ) Used to set the encoding format
| Parameters | explain |
|---|---|
| QLineEdit.Normal | Normal display of input characters , This is the default option |
| QLineEdit.NoEcho | No input characters are displayed , Commonly used for password type input , And the length is confidential |
| QLineEdit.Password | Display platform related password masking characters , Instead of the actual input character |
| QLineEdit.PasswordEchoOnEdit | Display characters when editing , Responsible for displaying password type input |
self.setInputMask( Parameters )
| Parameters | explain |
|---|---|
| 000.000.000.000;_ | ip Address , The white space character is ‘_’ |
| HH:HH:HH:HH:HH:HH; | MAC Address |
| 0000-00-00 | date , White space characters are spaces |
| >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# | License number , The white space character is ‘_’, All letters are capitalized |
self.setValidator() Set the verifier for the text box ( Validation rule ), Any text that may be entered will be restricted
| Parameters | explain |
|---|---|
| QIntValidator | Limit input integers |
| QDoubleValidator | Limit the input of floating point numbers |
| QRegexpValidator | Check that the input matches the regular expression |
QLineEdit Common signals
| selectionChanged | As long as you select the content to send the change, the signal will be sent |
|---|---|
| textChanged | When modifying text content , This signal will be transmitted |
| editingFinished | When editing text ends , This signal will be transmitted |
There are two ways to see the specific parameter requirements , Or go to the source code , Or read the official manual
The official manual looks like this , Reading the manual should be the fastest 

3. Text edit box QTextEdit And text browsing boxes QTextBrowser
4. Various button
5. label QLabel
6. Drop down the selection box comboBox
7. Digital adjustment box QSpinBox
8. Slider bar QSlider
9. knob QDial
10. Progress bar QProgressBar
11. Timer QTimer
12. Digital display QLCDNumber
13. Color dialog
14. Font selection dialog box
15. File selection dialog
边栏推荐
- A set of automated paperless office system (oa+ approval process) source code: with data dictionary
- 揭秘GaussDB(for Redis):全面对比Codis
- Ubuntu uninstalling PHP
- Error while sending STMT_ PREPARE packet. PID=29294
- Renrenyue -- renrenyue system development source code sharing
- Rank sum ratio comprehensive evaluation method for common models in mathematical modeling
- 一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
- Wait for the end of the network request in the uniapp Onshow method before executing the subsequent code content
- ECSHOP product attribute color specification size stock item No. automatic combination
- High performance + million level Excel data import and export
猜你喜欢

Navicat premium view password scheme

How do super rookies get started with data analysis?

Penetration tool environment - installing sqli labs in centos7 environment

Time series analysis - how to use unit root test (ADF) correctly?
![[on]learning dynamic and hierarchical traffic spatiotemporal features with transformer](/img/58/d68112a3d019de66150e2f5102f436.png)
[on]learning dynamic and hierarchical traffic spatiotemporal features with transformer

The first techo day Tencent technology open day in 2022 will be held online on June 28

20. MVVM command binding of WPF

K8s, docker compose install MySQL 8.0.18

Laravel excel export

2022 meisai topic C idea sharing + translation
随机推荐
Go novice exploration road 1
A commonly used statistical modeling method -- difference analysis
Zhengzheng e-commerce source code -- Zhengzheng advertising e-commerce system development source code sharing
Ubuntu uninstalling PHP
Swagger document generated by node project API in vscode
What is the primordial universe
Total number of MySQL statistics, used and unused
Network | indicators and test methods to measure the quality of the network
Wait for the end of the network request in the uniapp Onshow method before executing the subsequent code content
Arm immediate
Lighten the source code -- lighten the app system development function introduction to the beautiful world lighten the app system development source code in China
Time series analysis - how to use unit root test (ADF) correctly?
Disconnected: No supported authentication methods available (server sent: )
Hook technology
Découvrir gaussdb (pour redis): une comparaison complète avec Codis
The server reported an error 503 service unavailable:the system returned: (71) protocol error
The dist function of R language calculates the distance between two samples in dataframe data, returns the distance matrix between samples, and specifies the distance calculation method through the me
MySQL common interview questions
Spicy food advertising e-commerce system development function and spicy food advertising e-commerce app system development source code sharing
Rank sum ratio comprehensive evaluation method for common models in mathematical modeling