我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用PyQt5.QtGui.QDoubleValidator()。
def __init__(self, parent=None): QDialog.__init__(self, parent) self.ui = Ui_ShearDesignPreferences() self.ui.setupUi(self) self.main_controller = parent self.saved = None self.ui.combo_design_method.model().item(1).setEnabled(False) self.ui.combo_design_method.model().item(2).setEnabled(False) self.ui.tabWidget.removeTab(1) self.set_default_para() #int_validator = QIntValidator() dbl_validator = QDoubleValidator() self.ui.txt_boltFu.setValidator(dbl_validator) self.ui.txt_boltFu.setMaxLength(7) self.ui.txt_detailingGap.setValidator(dbl_validator) self.ui.txt_detailingGap.setMaxLength(4) self.ui.btn_defaults.clicked.connect(self.set_default_para) self.ui.btn_save.clicked.connect(self.save_designPref_para) self.ui.btn_close.clicked.connect(self.close_designPref) self.ui.combo_boltHoleType.currentIndexChanged[str].connect(self.set_bolthole_clearance)
def __init__(self, parent=None): QDialog.__init__(self, parent) self.ui = Ui_ShearDesignPreferences() self.ui.setupUi(self) self.main_controller = parent #self.uiobj = self.main_controller.uiObj self.saved = None self.ui.combo_design_method.model().item(1).setEnabled(False) self.ui.combo_design_method.model().item(2).setEnabled(False) self.set_default_para() dbl_validator = QDoubleValidator() self.ui.txt_boltFu.setValidator(dbl_validator) self.ui.txt_boltFu.setMaxLength(7) self.ui.txt_weldFu.setValidator(dbl_validator) self.ui.txt_weldFu.setMaxLength(7) self.ui.txt_detailingGap.setValidator(dbl_validator) self.ui.txt_detailingGap.setMaxLength(5) self.ui.btn_defaults.clicked.connect(self.set_default_para) self.ui.btn_save.clicked.connect(self.save_designPref_para) self.ui.btn_close.clicked.connect(self.close_designPref) self.ui.combo_boltHoleType.currentIndexChanged[str].connect(self.get_clearance)
def __init__(self, parent=None): QDialog.__init__(self, parent) self.ui = Ui_ShearDesignPreferences() self.ui.setupUi(self) self.main_controller = parent self.saved = None self.ui.combo_design_method.model().item(1).setEnabled(False) self.ui.combo_design_method.model().item(2).setEnabled(False) self.set_default_para() dbl_validator = QDoubleValidator() self.ui.txt_boltFu.setValidator(dbl_validator) self.ui.txt_boltFu.setMaxLength(7) self.ui.txt_weldFu.setValidator(dbl_validator) self.ui.txt_weldFu.setMaxLength(7) self.ui.btn_defaults.clicked.connect(self.set_default_para) self.ui.btn_save.clicked.connect(self.save_designPref_para) self.ui.btn_close.clicked.connect(self.close_designPref) self.ui.combo_boltHoleType.currentIndexChanged[str].connect(self.get_clearance)
def __init__(self, parent=None): QDialog.__init__(self, parent) self.ui = Ui_ShearDesignPreferences() self.ui.setupUi(self) self.main_controller = parent self.saved = None self.ui.combo_design_method.model().item(1).setEnabled(False) self.ui.combo_design_method.model().item(2).setEnabled(False) self.ui.tabWidget.removeTab(1) int_validator = QIntValidator() dbl_validator = QDoubleValidator() self.ui.txt_boltFu.setValidator(dbl_validator) self.ui.txt_boltFu.setMaxLength(7) self.ui.txt_detailingGap.setValidator(dbl_validator) self.ui.txt_detailingGap.setMaxLength(5) self.set_default_para() self.ui.btn_defaults.clicked.connect(self.set_default_para) self.ui.btn_save.clicked.connect(self.save_designPref_para) self.ui.btn_close.clicked.connect(self.close_designPref) self.ui.combo_boltHoleType.currentIndexChanged[str].connect(self.get_clearance)
def __init__(self, parent = None): QtGui.QDoubleValidator.__init__(self, parent) self.setNotation(QtGui.QDoubleValidator.StandardNotation)
def validatorChanged(self, index): if index == 0: self.validatorLineEdit.setValidator(0) elif index == 1: self.validatorLineEdit.setValidator(QIntValidator(self.validatorLineEdit)) elif index == 2: self.validatorLineEdit.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.validatorLineEdit)) self.validatorLineEdit.clear()
def validate(self, input, pos): state, input, pos = QtGui.QDoubleValidator.validate(self, input, pos) if state == QtGui.QValidator.Invalid: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif state == QtGui.QValidator.Intermediate: return (QtGui.QValidator.Intermediate, input, pos) if pos == 1: try: if float(str(input)) > 1: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) except: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif pos == 2: if not str(input)[pos-1] == ".": QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif pos > 2: try: if float(str(input)) > 1: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) except: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) return (QtGui.QValidator.Acceptable, input, pos) # Validator for integers
def validate(self, input, pos): state, input, pos = QtGui.QDoubleValidator.validate(self, input, pos) if state == QtGui.QValidator.Invalid: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif state == QtGui.QValidator.Intermediate: return (QtGui.QValidator.Intermediate, input, pos) if pos == 1: try: if float(str(input)) > 4: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) except: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif pos == 2: if not str(input)[pos-1] == ".": QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) elif pos > 2: try: if float(str(input)) >= 4: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) except: QtWidgets.QApplication.beep() return (QtGui.QValidator.Invalid, input, pos) return (QtGui.QValidator.Acceptable, input, pos) # Validator for table entry, rewrite the table
def setUi(self): self.temperatureLineEdit.setValidator(QDoubleValidator(self)) self.magneticFieldLineEdit.setValidator(QDoubleValidator(self)) self.e1MinLineEdit.setValidator(QDoubleValidator(self)) self.e1MaxLineEdit.setValidator(QDoubleValidator(self)) self.e1NPointsLineEdit.setValidator(QIntValidator(self)) self.e1LorentzianLineEdit.setValidator(QDoubleValidator(self)) self.e1GaussianLineEdit.setValidator(QDoubleValidator(self)) self.e2MinLineEdit.setValidator(QDoubleValidator(self)) self.e2MaxLineEdit.setValidator(QDoubleValidator(self)) self.e2NPointsLineEdit.setValidator(QIntValidator(self)) self.e2LorentzianLineEdit.setValidator(QDoubleValidator(self)) self.e2GaussianLineEdit.setValidator(QDoubleValidator(self)) self.nPsisLineEdit.setValidator(QIntValidator(self)) self.fkLineEdit.setValidator(QDoubleValidator(self)) self.gkLineEdit.setValidator(QDoubleValidator(self)) self.zetaLineEdit.setValidator(QDoubleValidator(self)) # Create the results model and assign it to the view. self.resultsModel = ListModel() self.resultsView.setModel(self.resultsModel) self.resultsView.setSelectionMode(QAbstractItemView.ExtendedSelection) self.resultsView.selectionModel().selectionChanged.connect( self.selectedCalculationsChanged) # Add a context menu. self.resultsView.setContextMenuPolicy(Qt.CustomContextMenu) self.createResultsContextMenu() self.resultsView.customContextMenuRequested[QPoint].connect( self.showResultsContextMenu) # Enable actions. self.elementComboBox.currentTextChanged.connect(self.resetCalculation) self.chargeComboBox.currentTextChanged.connect(self.resetCalculation) self.symmetryComboBox.currentTextChanged.connect(self.resetCalculation) self.experimentComboBox.currentTextChanged.connect( self.resetCalculation) self.edgeComboBox.currentTextChanged.connect(self.resetCalculation) self.magneticFieldLineEdit.editingFinished.connect( self.updateMagneticField) self.e1GaussianLineEdit.editingFinished.connect(self.updateBroadening) self.e2GaussianLineEdit.editingFinished.connect(self.updateBroadening) self.kinLineEdit.editingFinished.connect(self.updateIncidentWaveVector) self.einLineEdit.editingFinished.connect( self.updateIncidentPolarizationVector) self.nPsisAutoCheckBox.toggled.connect(self.updateNPsisLineEditState) self.fkLineEdit.editingFinished.connect(self.updateScalingFactors) self.gkLineEdit.editingFinished.connect(self.updateScalingFactors) self.zetaLineEdit.editingFinished.connect(self.updateScalingFactors) self.saveInputAsPushButton.clicked.connect(self.saveInputAs) self.calculationPushButton.clicked.connect(self.runCalculation)