def init(self): # create a formLayout form_layout = QFormLayout(self) int_line_edit = QLineEdit() double_line_edit = QLineEdit() reg_line_edit = QLineEdit() form_layout.addRow("int", int_line_edit) form_layout.addRow("double", double_line_edit) form_layout.addRow("regular", reg_line_edit) int_line_edit.setPlaceholderText("int") double_line_edit.setPlaceholderText("double") reg_line_edit.setPlaceholderText("regular") int_validator = QIntValidator() int_validator.setRange(1, 99) double_validator = QDoubleValidator() double_validator.setRange(-100, 100) double_validator.setNotation(QDoubleValidator.StandardNotation) double_validator.setDecimals(2) reg_validator = QRegExpValidator() reg_validator.setRegExp(QRegExp('[0-9a-zA-Z]')) # set validator int_line_edit.setValidator(int_validator) double_line_edit.setValidator(double_validator) reg_line_edit.setValidator(reg_validator) self.setLayout(form_layout)
def initUI(self): self.setWindowTitle('校验器') formLayout = QFormLayout() IntLineEdit = QLineEdit() DoubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() formLayout.addRow('int', IntLineEdit) formLayout.addRow('double', DoubleLineEdit) formLayout.addRow('数字和字母', validatorLineEdit) IntLineEdit.setPlaceholderText('整型') #整数校验器1-99 intValidator = QIntValidator(self) intValidator.setRange(1, 99) #浮点 doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-360, 360) doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(2) #小数点2位 #字符和数字 reg = QRegExp('[a-zA-Z0-9]+$') validator = QRegExpValidator(self) validator.setRegExp(reg) #设置校验器 IntLineEdit.setValidator(intValidator) DoubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(validator) self.setLayout(formLayout)
def initUI(self): self.setWindowTitle('校验器') formLayout = QFormLayout() intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() regLineEdit = QLineEdit() formLayout.addRow('整数', intLineEdit) formLayout.addRow('浮点数', doubleLineEdit) formLayout.addRow('正则表达式', regLineEdit) intLineEdit.setPlaceholderText('整型数字') doubleLineEdit.setPlaceholderText('浮点数') regLineEdit.setPlaceholderText('正则表达式') intValidator = QIntValidator() intValidator.setRange(0, 1000) doubleValidator = QDoubleValidator() doubleValidator.setRange(-100, 100) doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(2) # 小数精度 reg = QRegExp(r"[a-zA-Z0-9]+$") regValidator = QRegExpValidator(self) regValidator.setRegExp(reg) # 设置校验器 intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) regLineEdit.setValidator(regValidator) self.setLayout(formLayout)
def init(self): # 开始按键 self.pushButton.clicked.connect(self.pushButton_event) # 结束按键 self.pushButton_2.clicked.connect(self.pushButton_event2) # 限制为数字和字符 self.lineEdit.setPlaceholderText("只能键入数字和字符") reg = QRegExp("[a-zA-Z0-9]+$") LE1Validator = QRegExpValidator(self) LE1Validator.setRegExp(reg) self.lineEdit.setValidator(LE1Validator) #设置浮点数限制 范围0~86400,小数点1位 LE2Validator = QDoubleValidator(self) LE2Validator.setRange(0, 86400) LE2Validator.setNotation(QDoubleValidator.StandardNotation) LE2Validator.setDecimals(1) self.lineEdit_2.setValidator(LE2Validator) self.lineEdit_2.setPlaceholderText("最小为0.1s") self.lineEdit_3.setValidator(LE2Validator) self.lineEdit_3.setPlaceholderText("最小为0.1s") # 启动后台 self.lk.start()
def initUI(self): self.add_sensor_confirm.clicked.connect(self.insert_sensor_into_db) self.add_sensor_cancle.clicked.connect(self.close) self.voltage1_input.textChanged.connect(self.updateUI) self.voltage2_input.textChanged.connect(self.updateUI) self.pressure1_input.textChanged.connect(self.updateUI) self.pressure2_input.textChanged.connect(self.updateUI) self.value2_input.textChanged.connect(self.updateUI) self.value1_input.textChanged.connect(self.updateUI) doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-10000, 10000) doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(4) self.value1_input.setValidator(doubleValidator) self.value2_input.setValidator(doubleValidator) self.pressure2_input.setValidator(doubleValidator) self.pressure1_input.setValidator(doubleValidator) self.voltage2_input.setValidator(doubleValidator) self.voltage1_input.setValidator(doubleValidator) self.vp_input.setValidator(doubleValidator) self.zv_input.setValidator(doubleValidator) self.pt_input.setValidator(doubleValidator) self.pu_input.setValidator(doubleValidator) self.ad2_max_input.setValidator(doubleValidator) self.pp_input.setValidator(doubleValidator) self.resulotion_input.setValidator(doubleValidator)
class LineEdit(QLineEdit): checkVal = pyqtSignal(float) def __init__(self, *args, **kwargs): super(LineEdit, self).__init__(*args, **kwargs) self.validator = QDoubleValidator() self.setValidator(self.validator) self.textChanged.connect(self.new_text) self.returnPressed.connect(self.check_validator) self.ntext = self.text() def new_text(self, text): if self.hasAcceptableInput(): self.ntext = text def keyPressEvent(self, event): super().keyPressEvent(event) if event.key() == Qt.Key_Return and not self.hasAcceptableInput(): self.check_validator() def check_validator(self): try: if float(self.text()) > self.validator.top(): self.setText(str(self.validator.top())) elif float(self.text()) < self.validator.bottom(): self.setText(str(self.validator.bottom())) except ValueError: QMessageBox.about(self, "Error", "Input can only be a number") self.setText(self.ntext) self.checkVal.emit(float(self.ntext)) def valRange(self, x1, x2): self.validator.setRange(x1, x2) self.validator.setDecimals(6) self.validator.setNotation(QDoubleValidator.StandardNotation)
def __init__(self, parent=None): super(LineEditDemo, self).__init__(parent) self.setWindowTitle('QLineEdit Validator sample') flo = QFormLayout() pIntLineEdit = QLineEdit() pDoubleLineEdit = QLineEdit() pValidatorLineEdit = QLineEdit() flo.addRow('Integer', pIntLineEdit) flo.addRow('Float', pDoubleLineEdit) flo.addRow('Letter and number', pValidatorLineEdit) pIntLineEdit.setPlaceholderText('Integer') pDoubleLineEdit.setPlaceholderText('Float') pValidatorLineEdit.setPlaceholderText('Letter and number') pIntValidator = QIntValidator(self) pIntValidator.setRange(1, 99) pDoubleValidator = QDoubleValidator(self) pDoubleValidator.setRange(-100, 100) pDoubleValidator.setNotation(QDoubleValidator.StandardNotation) pDoubleValidator.setDecimals(2) reg = QRegExp("[a-zA-Z0-9]+$") pValidator = QRegExpValidator(self) pValidator.setRegExp(reg) pIntLineEdit.setValidator(pIntValidator) pDoubleLineEdit.setValidator(pDoubleValidator) pValidatorLineEdit.setValidator(pValidator) self.setLayout(flo)
def initUI(self): self.setWindowTitle("校验器") formlayout = QFormLayout(self) intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() formlayout.addRow("整数类型", intLineEdit) formlayout.addRow("浮点类型", doubleLineEdit) formlayout.addRow("数字和字母", validatorLineEdit) intLineEdit.setPlaceholderText("整数类型") doubleLineEdit.setPlaceholderText("浮点类型") validatorLineEdit.setPlaceholderText("数字和字母") intValidator = QIntValidator(self) intValidator.setRange(1, 99) floatValidator = QDoubleValidator(self) floatValidator.setRange(-360, 360) floatValidator.setNotation(QDoubleValidator.StandardNotation) floatValidator.setDecimals(2) reg = QRegExp('[a-zA-z0-9]+$') validator = QRegExpValidator(self) validator.setRegExp(reg) intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(floatValidator) validatorLineEdit.setValidator(validator)
def initUI(self): self.setWindowTitle('校验器') intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() regExpLineEdit = QLineEdit() intLineEdit.setPlaceholderText('整数') doubleLineEdit.setPlaceholderText('小数') regExpLineEdit.setPlaceholderText('字母和数字') # 创建校验器 intValidator = QIntValidator(self) intValidator.setRange(1, 50) # [1,50]取值范围 doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-100, 100, 2) # [-100,100]小数点后两位 doubleValidator.setNotation( QDoubleValidator.StandardNotation) # 标准化将字符串转为double regExpValidator = QRegExpValidator(self) reg = QRegExp('[a-zA-Z0-9]+$') regExpValidator.setRegExp(reg) # 设置校验器 intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) regExpLineEdit.setValidator(regExpValidator) formLayout = QFormLayout() formLayout.addRow('整型类型', intLineEdit) formLayout.addRow('浮点类型', doubleLineEdit) formLayout.addRow('数字和字母', regExpLineEdit) self.setLayout(formLayout)
def ui(self): layout = QFormLayout(self) for k, v in self.parameters.items(): if v['kind'] == ParameterDialog.ComboBox: comboBox = QComboBox() comboBox.addItems(v['items']) layout.addRow(k, comboBox) elif v['kind'] == ParameterDialog.FloatSlider: f = lambda n: v['min'] + n / 100 * (v['max'] - v['min']) g = lambda x: int((x - v['min']) / (v['max'] - v['min']) * 100) slider = QSlider(Qt.Horizontal) slider.setMinimum(0) slider.setMaximum(100) slider.setSingleStep(1) slider.setValue(g(v['init'])) le = QLineEdit() le.setPlaceholderText(v['init']) dv = QDoubleValidator(self) dv.setRange(v['min'], v['max']) dv.setNotation(QDoubleValidator.StandardNotation) dv.setDecimals(2) le.setValidator(dv) # slider.valueChanged.connect(lambda n: le.setText(f(n))) # le.textChanged.connect(lambda x: slider.setValue(g(x))) hlayout = QHBoxLayout() hlayout.addWidget(slider, alignment=Qt.AlignLeft) hlayout.addWidget(le, alignment=Qt.AlignRight) layout.addRow(k, hlayout) self.setLayout(layout)
def init_ui(self): self.setWindowTitle('教验器') #创建表单布局 formLayout = QFormLayout(self) intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() formLayout.addRow("整型", intLineEdit) formLayout.addRow("浮点型", doubleLineEdit) formLayout.addRow("数字和字母", validatorLineEdit) #int validator intValidator = QIntValidator(self) intValidator.setRange(1, 99) #double validator doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-360, 360) doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(2) #validator reg = QRegExp('[a-zA-Z0-9]+$') validator = QRegExpValidator() validator.setRegExp(reg) #设置jiaoyanqi intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(validator) self.setLayout(formLayout)
def initGUI(self): self.setWindowTitle("校验器") formlayout = QFormLayout() intLineEdit = QLineEdit(self) doubleLineEdit = QLineEdit(self) validatorLineEdit = QLineEdit(self) formlayout.addRow("整数校验", intLineEdit) formlayout.addRow("浮点校验", doubleLineEdit) formlayout.addRow("数字和字母校验", validatorLineEdit) intLineEdit.setPlaceholderText("请输入整数") doubleLineEdit.setPlaceholderText("请输入浮点数") validatorLineEdit.setPlaceholderText("请输入数字和字母") intValidator = QIntValidator(self) intValidator.setRange(1, 10) doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-180, 180) doubleValidator.setNotation(QDoubleValidator.StandardNotation) # 小数点后两位 doubleValidator.setDecimals(2) reg = QRegExp('[a-zA-Z0-9]+$') regValidator = QRegExpValidator(self) regValidator.setRegExp(reg) intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(regValidator) self.setLayout(formlayout)
def __init__(self, parent=None): super(MainWin, self).__init__(parent) flo = QFormLayout() pIntLineEdit = QLineEdit() pDoubleLineEdit = QLineEdit() pValidatorLineEdit = QLineEdit() flo.addRow('整數', pIntLineEdit) flo.addRow('浮點數', pDoubleLineEdit) flo.addRow('字母和數字', pValidatorLineEdit) pIntLineEdit.setPlaceholderText('整數') pDoubleLineEdit.setPlaceholderText('浮點數') pValidatorLineEdit.setPlaceholderText('字母和數字') pIntValidator = QIntValidator(self) pIntValidator.setRange(1, 99) pDoubleValidator = QDoubleValidator(self) pDoubleValidator.setRange(-360, 360) pDoubleValidator.setNotation(QDoubleValidator.StandardNotation) pDoubleValidator.setDecimals(2) reg = QRegExp('[a-zA-Z0-9]+$') pValidator = QRegExpValidator(self) pValidator.setRegExp(reg) pIntLineEdit.setValidator(pIntValidator) pDoubleLineEdit.setValidator(pDoubleValidator) pValidatorLineEdit.setValidator(pValidator) self.setLayout(flo) self.setWindowTitle('QLineEdit範例')
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setFixedHeight(525) self.setupUi(self) #Init GUI elements validator = QDoubleValidator() validator.setNotation(QtGui.QDoubleValidator.StandardNotation) validator.setRange(0, 50.00, 2) self.pizzaPrice_LE_1.setValidator(validator) self.pizzaPrice_LE_2.setValidator(validator) self.pizzaPrice_LE_3.setValidator(validator) self.pizzaPrice_LE_4.setValidator(validator) self.pizza_round_label.setHidden(True) self.pizza_quad_label.setHidden(True) self.missing_Input_Label.setHidden(True) self.diagram_GV.setHidden(True) #signals (events) self.calculate_PB.clicked.connect(self.check_Inputs_AndCalc) self.clear_PB.clicked.connect(self.clear_all_LE) self.length_verticalSlider.valueChanged.connect(self.set_length) self.width_verticalSlider.valueChanged.connect(self.set_width) self.hiddenButton_PB.clicked.connect(self.show_images) self.diagram_PB.clicked.connect(self.show_diagram) self.diagram_GV.setBackground('#baa7ba') styles = {'color': 'y', 'font-size': '18px'} self.diagram_GV.setLabel('left', 'rel. Preis [Cent/cm²]', **styles) self.diagram_GV.setLabel('bottom', 'Pizzafläche [cm²]', **styles) pen = pg.mkPen(color=(0, 0, 0), width=1) self.diagram_GV.plotItem.getAxis('left').setPen(pen) self.diagram_GV.plotItem.getAxis('left').setTextPen(pen) self.diagram_GV.plotItem.getAxis('bottom').setPen(pen) self.diagram_GV.plotItem.getAxis('bottom').setTextPen(pen)
def initUI(self): self.setWindowTitle('QlineLabel校验器') formlayout = QFormLayout(self) intLineEdit = QLineEdit() doubleLineEidt = QLineEdit() validatorLineEdit = QLineEdit() formlayout.addRow('整数类型', intLineEdit) formlayout.addRow('浮点数 ', doubleLineEidt) formlayout.addRow('数字字母', validatorLineEdit) intLineEdit.setPlaceholderText('整数') doubleLineEidt.setPlaceholderText('浮点数') validatorLineEdit.setPlaceholderText('字母') # 整数校验器 intValidator = QIntValidator(self) intValidator.setRange(1, 99) doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-360, 360) doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(2) reg = QRegExp('[a-zA-Z0-9]+$') validator = QRegExpValidator(self) validator.setRegExp(reg) intLineEdit.setValidator(intValidator) doubleLineEidt.setValidator(doubleValidator) validatorLineEdit.setValidator(validator)
def initUI(self): self.setWindowTitle("校验器") #创建表单布局 formlayout = QFormLayout() intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() formlayout.addRow("整数类型", intLineEdit) formlayout.addRow("浮点类型", doubleLineEdit) formlayout.addRow("数字和字母", validatorLineEdit) intLineEdit.setPlaceholderText("整型") doubleLineEdit.setPlaceholderText("浮点") validatorLineEdit.setPlaceholderText("字母和数字") # 整数校验器 intValidator = QIntValidator(self) intValidator.setRange(1, 99) #浮点校验器 doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-360, 360) doubleValidator.setNotation(QDoubleValidator.StandardNotation) #设置精度,小数点2位 doubleValidator.setDecimals(2) #字符和数字 reg = QRegExp('[a-zA-Z0-9]+$') validator = QRegExpValidator(self) validator.setRegExp(reg) #设置校验器 intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(validator) self.setLayout(formlayout)
def initUI(self): formLayout = QFormLayout() intLine = QLineEdit() doubletLine = QLineEdit() validatortLine = QLineEdit() formLayout.addRow("int", intLine) formLayout.addRow("double", doubletLine) formLayout.addRow("字母数字", validatortLine) # int validator intValidator = QIntValidator() intValidator.setRange(1, 99) # 浮点,小数点后两位 doubleValidator = QDoubleValidator() doubleValidator.setRange(1, 99) # doubleValidator.setNotation(QDoubleValidator.StandardNotation) # 精度,小数点两位 doubleValidator.setDecimals(2) # 数字字符 reg = QRegExp('[a-zA-Z0-9]+$') validator = QRegExpValidator() validator.setRegExp(reg) intLine.setValidator(intValidator) doubletLine.setValidator(doubleValidator) validatortLine.setValidator(validator) self.setLayout(formLayout)
def initUI(self): self.setWindowTitle("校验器") formlayout = QFormLayout() INT = QLineEdit() DOUBLE = QLineEdit() REG = QLineEdit() formlayout.addRow("整数类型", INT) formlayout.addRow("浮点数", DOUBLE) formlayout.addRow("数字和字母", REG) INT.setPlaceholderText("整型") DOUBLE.setPlaceholderText("浮点型") REG.setPlaceholderText("字母和数字") intvalidator = QIntValidator(self) intvalidator.setRange(1, 99) doublevalidator = QDoubleValidator(self) doublevalidator.setRange(-360, 360) doublevalidator.setNotation(QDoubleValidator.StandardNotation) #标准显示法 doublevalidator.setDecimals(2) #设置精度 reg = QRegExp('[a-zA-Z0-9]+$') RegExpValidator = QRegExpValidator(self) RegExpValidator.setRegExp(reg) #设置校验器 INT.setValidator(intvalidator) DOUBLE.setValidator(doublevalidator) REG.setValidator(RegExpValidator) self.setLayout(formlayout)
def init_lineedit_content(self): # 入职前工作年限,格式应该为纯数字 double_valitor = QDoubleValidator() double_valitor.setRange(0, 100) double_valitor.setDecimals(1) self.strongsuit.setValidator(double_valitor) # 出生日期、雇佣日期,格式yyyy-MM-DD reg = QRegExp('^[23][0-9]{3}-[0-9]{2}-[0-9]{2}$') day_validator = QRegExpValidator() day_validator.setRegExp(reg) self.birthday.setValidator(day_validator) self.entranceday.setValidator(day_validator) # 匹配身份证 reg = QRegExp('^\d{17}(\d|X)$') id_validator = QRegExpValidator() id_validator.setRegExp(reg) self.idno.setValidator(id_validator) # 匹配电话号码,纯数字 reg = QRegExp('[0-9]{11}') tel_validator = QRegExpValidator() tel_validator.setRegExp(reg) self.telno.setValidator(tel_validator)
def setUI(self): self.setWindowTitle('校验器') formLayout = QFormLayout() intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() formLayout.addRow('整数类型', intLineEdit) formLayout.addRow('浮点类型', doubleLineEdit) formLayout.addRow('数字和字母', validatorLineEdit) intLineEdit.setPlaceholderText('整形') doubleLineEdit.setPlaceholderText('浮点型') validatorLineEdit.setPlaceholderText('字母和数字') #整数校验器 intValidator = QIntValidator(self) intValidator.setRange(1, 99) #浮点数校验器 doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-360, 360) doubleValidator.setNotation(QDoubleValidator.StandardNotation) #设置精度 doubleValidator.setDecimals(2) #字母和数字 reg = QRegExp('[a-zA-z0-9]+$') validator = QRegExpValidator(self) validator.setRegExp(reg) #设置校验器 intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(validator) self.setLayout(formLayout)
def set_validator(self): intvalidator = QIntValidator() intvalidator.setBottom(0) self.lineEdit_precision.setValidator(intvalidator) doublevalidator = QDoubleValidator() doublevalidator.setRange(0, 100) self.lineEdit_loss.setValidator(doublevalidator)
def initUI(self): lineedit1 = QLineEdit() lineedit2 = QLineEdit() lineedit3 = QLineEdit() # 整数验证 intValidator = QIntValidator(self) # 如何1到111? intValidator.setRange(1, 99) # 正则验证 regvalidator = QRegExpValidator(self) reg = QRegExp("^[A-Z][0-9]{2}$") regvalidator.setRegExp(reg) # 浮点型验证 doubleValidator = QDoubleValidator(self) doubleValidator.setRange(-99, 99) # 作用是什么 doubleValidator.setNotation(QDoubleValidator.StandardNotation) doubleValidator.setDecimals(2) lineedit1.setValidator(intValidator) lineedit2.setValidator(regvalidator) lineedit3.setValidator(doubleValidator) lineedit2.setPlaceholderText('字母数字数字') formlayout = QFormLayout() formlayout.addRow('数字', lineedit1) formlayout.addRow('正则', lineedit2) formlayout.addRow('两位小数', lineedit3) self.setLayout(formlayout)
def __init__(self, parent=None): super(lineEditDemo, self).__init__(parent) self.setWindowTitle('QLineEdit例子') flo = QFormLayout() pIntlineEdit = QLineEdit() pDoublelineEdit = QLineEdit() pValidatorlineEdit = QLineEdit() flo.addRow('整型', pIntlineEdit) flo.addRow('浮点型', pDoublelineEdit) flo.addRow('字母、数字和下划线', pValidatorlineEdit) pIntlineEdit.setPlaceholderText('整型') pDoublelineEdit.setPlaceholderText('浮点型') pValidatorlineEdit.setPlaceholderText('字母、数字和下划线') pIntValidator = QIntValidator(self) pIntValidator.setRange(0, 99) pDoubleValidator = QDoubleValidator(self) pDoubleValidator.setRange(-360, 360) pDoubleValidator.setNotation( QDoubleValidator.StandardNotation) # 分标准浮点记数和科学浮点记数 pDoubleValidator.setDecimals(2) r = QRegExp(r'^[a-zA-Z0-9\_]+$') pReValidator = QRegExpValidator(self) pReValidator.setRegExp(r) pIntlineEdit.setValidator(pIntValidator) pDoublelineEdit.setValidator(pDoubleValidator) pValidatorlineEdit.setValidator(pReValidator) self.setLayout(flo)
def set_backamount_validator(self): doublevalidator = QDoubleValidator() try: max_float = decimal.Decimal(self.lineEdit_restamount.text()) doublevalidator.setRange(0, max_float) except decimal.InvalidOperation: doublevalidator.setBottom(0) self.lineEdit_backamount.setValidator(doublevalidator)
def set_valitor(self): doublevalitor = QDoubleValidator() try: doublevalitor.setRange(0, self.item['amount'], 4) except KeyError: pass doublevalitor.setNotation(QDoubleValidator.StandardNotation) self.lineEdit_drawamount.setValidator(doublevalitor)
def settings(self): doubleValidator1 = QDoubleValidator(self) doubleValidator1.setRange(0, 500000) doubleValidator2 = QDoubleValidator(self) doubleValidator2.setRange(0, 1) self.maxvolume_A.setValidator(doubleValidator1) self.maxvolume_B.setValidator(doubleValidator1) self.pump_rate_A.setValidator(doubleValidator2) self.pump_rate_B.setValidator(doubleValidator2)
def set_restamount_validator(self): doublevalidator = QDoubleValidator() try: max_float = self.ori_detail['drawamount'] pracamount = decimal.Decimal(self.lineEdit_pracamount.text()) doublevalidator.setRange(0, max_float - pracamount) except (KeyError, decimal.InvalidOperation): doublevalidator.setBottom(0) self.lineEdit_restamount.setValidator(doublevalidator)
def __init__(self, parent=None): super(lineEditDemo, self).__init__(parent) self.setWindowTitle('QLineEdit例子') #实例化表单布局 flo = QFormLayout() #创建三个文本框 pIntLineEdit = QLineEdit() pDoubleLineEdit = QLineEdit() pValidatorLineEdit = QLineEdit() #表单布局添加名称及控件 flo.addRow('整型', pIntLineEdit) flo.addRow('浮点型', pDoubleLineEdit) flo.addRow('字母和数字', pValidatorLineEdit) #设置文本框的默认浮现文本 pIntLineEdit.setPlaceholderText('整型') pDoubleLineEdit.setPlaceholderText('浮点型') pValidatorLineEdit.setPlaceholderText('字母和数字') #整型 范围 【1-99】 #实例化整型验证器,并设置范围为1-99 pIntvalidator = QIntValidator(self) pIntvalidator.setRange(1, 999999) #浮点型 范围 【-360,360】,精度 小数点后两位 #实例化浮点验证器,设置范围-360到360 pDoubleValidator = QDoubleValidator() pDoubleValidator.setRange(-3600, 3600) pDoubleValidator.setNotation(QDoubleValidator.StandardNotation) #设置精度小数点后两位 pDoubleValidator.setDecimals(2) #字母和数字 #设置文本允许出现的字符内容 reg = QRegExp('[a-zA-Z0-9]+$') #自定义文本验证器 pValidator = QRegExpValidator(self) #设置属性 pValidator.setRegExp(reg) #设置验证器 pIntLineEdit.setValidator(pIntvalidator) pDoubleLineEdit.setValidator(pDoubleValidator) pValidatorLineEdit.setValidator(pValidator) self.setLayout(flo)
def set_pracamount_validator(self): doublevalidator = QDoubleValidator() try: max_float = self.ori_detail['drawamount'] doublevalidator.setRange(0, max_float) except KeyError: doublevalidator.setBottom(0) self.lineEdit_pracamount.setValidator(doublevalidator) doubleValitor = QDoubleValidator() doubleValitor.setRange(-360, 360) doubleValitor.setDecimals(2) doubleValitor.setNotation(QDoubleValidator.StandardNotation)
def initUI(self): self.setWindowTitle('QLineEdit控件的校验器') # 创建表单布局对象 formLayout = QFormLayout() # 创建三个QLineEdit控件 intLineEdit = QLineEdit() doubleLineEdit = QLineEdit() validatorLineEdit = QLineEdit() # 将控件添加到布局中 formLayout.addRow('整数类型', intLineEdit) formLayout.addRow('浮点类型', doubleLineEdit) formLayout.addRow('字母和数字(正则表达式)', validatorLineEdit) # 为QLineEdit控添默认提示内容 intLineEdit.setPlaceholderText('整数') doubleLineEdit.setPlaceholderText('浮点') validatorLineEdit.setPlaceholderText('字母和数字') """ 1.设置整数校验器(只能输入[1,99]之间的整数) """ # 创建QDoubleValidator校验器对象 intValidator = QIntValidator(self) # 设置校验范围 intValidator.setRange(1, 99) """ 2.设置浮点校验器(只能输入[-99.xx,99.xx],精度要求保留小数点后2位) """ # 创建QDoubleValidator校验器对象 doubleValidator = QDoubleValidator(self) # 设置校验范围 doubleValidator.setRange(-99, 99) # 正常显示浮点数 doubleValidator.setNotation(QDoubleValidator.StandardNotation) # 设置精度,保留小数点后两位 doubleValidator.setDecimals(2) """ 3.设置字母和数字(正则表达式)校验器 """ # 正则表达式 reg = QRegExp('[a-zA-Z0-9]+$') # 正则表达式校验器 validator = QRegExpValidator(self) # 将正则表达式和正则表达式校验器绑定到一起 validator.setRegExp(reg) """ 设置校验器:绑定校验器和控件 """ intLineEdit.setValidator(intValidator) doubleLineEdit.setValidator(doubleValidator) validatorLineEdit.setValidator(validator) # 应用表单布局 self.setLayout(formLayout)
def __init__(self, parent=None): super(lineEditDemo, self).__init__(parent) self.setWindowTitle("QLineEdit例子") flo = QFormLayout() pIntLineEdit = QLineEdit( ) pDoubleLineEdit = QLineEdit() pValidatorLineEdit = QLineEdit( ) flo.addRow("整形", pIntLineEdit) flo.addRow("浮点型", pDoubleLineEdit) flo.addRow("字母和数字", pValidatorLineEdit) pIntLineEdit.setPlaceholderText("整形"); pDoubleLineEdit.setPlaceholderText("浮点型"); pValidatorLineEdit.setPlaceholderText("字母和数字"); # 整形 范围:[1, 99] pIntValidator = QIntValidator(self) pIntValidator.setRange(1, 99) # 浮点型 范围:[-360, 360] 精度:小数点后2位 pDoubleValidator = QDoubleValidator(self) pDoubleValidator.setRange(-360, 360) pDoubleValidator.setNotation(QDoubleValidator.StandardNotation) pDoubleValidator.setDecimals(2) # 字符和数字 reg = QRegExp("[a-zA-Z0-9]+$") pValidator = QRegExpValidator(self) pValidator.setRegExp(reg) # 设置验证器 pIntLineEdit.setValidator(pIntValidator) pDoubleLineEdit.setValidator(pDoubleValidator) pValidatorLineEdit.setValidator(pValidator) self.setLayout(flo)