当前位置:网站首页>33 restrict the input of qlineedit control (verifier)
33 restrict the input of qlineedit control (verifier)
2022-07-03 22:29:00 【bus_ lupe】
Limit input to integers only 、 Floating point number or string satisfying certain conditions
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIntValidator, QDoubleValidator, QRegExpValidator
from PyQt5.QtCore import QRegExp
import sys
class QLineEditValidator(QWidget):
def __init__(self):
super(QLineEditValidator, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle(' Calculator ')
# Create form layout
formLayout = QFormLayout()
intLineEdit = QLineEdit()
doubleLineEdit = QLineEdit()
regLineEdit = QLineEdit()
intLineEdit.setPlaceholderText(' Integers ')
doubleLineEdit.setPlaceholderText(' floating-point ')
regLineEdit.setPlaceholderText(' Letters and numbers ')
# Integer verifier [1, 99]
intValidator = QIntValidator(self)
intValidator.setRange(1, 99)
# Floating point verifier [-360, 360], precision : Two decimal places
doubleValidator = QDoubleValidator(self)
doubleValidator.setRange(-360, 360)
doubleValidator.setNotation(QDoubleValidator.StandardNotation)
# Setting accuracy , Two decimal places
doubleValidator.setDecimals(2)
# Characters and numbers
reg = QRegExp('[a-zA-Z0-9]+$')
validator = QRegExpValidator(self)
validator.setRegExp(reg)
# Set the calibrator
intLineEdit.setValidator(intValidator)
doubleLineEdit.setValidator(doubleValidator)
regLineEdit.setValidator(validator)
formLayout.addRow(' Integer types ', intLineEdit)
formLayout.addRow(' Floating point type ', doubleLineEdit)
formLayout.addRow(' Alphanumeric ', regLineEdit)
self.setLayout(formLayout)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QLineEditValidator()
main.show()
sys.exit(app.exec_())
边栏推荐
- Awk getting started to proficient series - awk quick start
- Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
- string
- [sg function] lightoj Partitioning Game
- IDENTITY
- Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
- Covariance
- Flutter internationalized Intl
- Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
- Farmersworld farmers world, no faith, how to talk about success?
猜你喜欢
QGIS grid processing DEM data reclassification
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
The reason why the computer runs slowly and how to solve it
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
Preliminary analysis of smart microwave radar module
1068. Consolidation of ring stones (ring, interval DP)
The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
Firefox set up proxy server
Pat grade A - 1164 good in C (20 points)
随机推荐
Conditional statements of shell programming
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
Flutter internationalized Intl
[Android reverse] use the DB browser to view and modify the SQLite database (copy the database file from the Android application data directory | use the DB browser tool to view the data block file)
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
How to solve win10 black screen with only mouse arrow
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
4 environment construction -standalone ha
Yyds dry goods inventory Prometheus alarm Art
Redis single thread and multi thread
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
Programming language (2)
Codeforces Round #768 (Div. 1)(A-C)
Preliminary analysis of smart microwave radar module
Pat grade A - 1164 good in C (20 points)
This time, thoroughly understand bidirectional data binding 01
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
[automation operation and maintenance novice village] flask-2 certification