当前位置:网站首页>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_())
边栏推荐
- Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
- User login function: simple but difficult
- Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
- BUUCTF,Misc:LSB
- [dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
- 国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
- js demo 计算本年度还剩下多少天
- Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
- Blue Bridge Cup -- Mason prime
- 4 environment construction -standalone ha
猜你喜欢

Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)

Firefox set up proxy server

2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions

Blue Bridge Cup -- Mason prime

Pat grade A - 1164 good in C (20 points)

Learning notes of raspberry pie 4B - IO communication (SPI)

Buuctf, misc: sniffed traffic

The difference between SRAM and DRAM

pivot ROP Emporium

QGIS grid processing DEM data reclassification
随机推荐
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
On my first day at work, this API timeout optimization put me down!
3 environment construction -standalone
How to obtain opensea data through opensea JS
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
4 environment construction -standalone ha
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
AST (Abstract Syntax Tree)
Quick one click batch adding video text watermark and modifying video size simple tutorial
Awk getting started to proficient series - awk quick start
Oil monkey plug-in
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Farmersworld farmers world, no faith, how to talk about success?
Team collaborative combat penetration tool CS artifact cobalt strike
Codeforces Round #768 (Div. 1)(A-C)
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
Rest参考
C deep anatomy - the concept of keywords and variables # dry inventory #
Buuctf, misc: n solutions
To rotate 90 degrees clockwise and modify the video format