def in_box(self,w=250,h=30,x=210,y=50,echo_mode=False,place_hldr=''): inp = QLineEdit(self) inp.setFixedSize(w,h) inp.move(x,y) inp.setPlaceholderText(place_hldr) inp.setFont(QFont("Times New Roman",14)) if echo_mode: inp.setValidator(QDoubleValidator(0.99,99.99,2)) return inp
def setup_validators(self): int_validator = QIntValidator() int_validator.setBottom(0) double_validator = QDoubleValidator() double_validator.setBottom(0.) self.tube_count_line.setValidator(int_validator) self.flowrate_line.setValidator(double_validator) self.value1_line.setValidator(double_validator) self.value2_line.setValidator(double_validator)
def _set_validators(self): """Set validators on edit fields.""" self.leNumEpochs.setValidator(QIntValidator(1, 1000000000, self)) self.leLearningRate.setValidator(QDoubleValidator(0.0, 1.0, 8, self)) self.leWeightDecay.setValidator(QDoubleValidator(0.0, 1.0, 8, self)) self.leMomentum.setValidator(QDoubleValidator(0.0, 1.0, 8, self)) self.leGlobalIntMin.setValidator(QIntValidator(0, 1000000000, self)) self.leGlobalIntMax.setValidator(QIntValidator(0, 1000000000, self)) self.leSamplesPerImage.setValidator(QIntValidator(1, 1000000000, self)) self.leNumEpochs.setValidator(QIntValidator(1, 1000000000, self)) self.leValidationStep.setValidator(QIntValidator(1, 1000000000, self)) self.leTrainingBatchSize.setValidator( QIntValidator(1, 1000000000, self)) self.lineEditROIHeight.setValidator(QIntValidator(1, 1000000000, self)) self.lineEditROIWidth.setValidator(QIntValidator(1, 1000000000, self)) self.leNumWorkers.setValidator(QIntValidator(0, 1000000000, self)) self.leSlidingWindowBatchSize.setValidator( QIntValidator(1, 1000000000, self))
def create_validator(self): validator = QDoubleValidator(self.parent) if "min" in self.config: validator.setBottom(int(self.config["min"])) if "max" in self.config: validator.setTop(int(self.config["max"])) if "decimals" in self.config: validator.setDecimals(int(self.config["decimals"])) return validator
def do_chi_options(self): self.chi_options = QGroupBox('') lt = QHBoxLayout() self.chi_regress_options = QGroupBox("") layout = QFormLayout() self.chi_minA = QLineEdit() self.chi_minA.setValidator(QDoubleValidator()) self.chi_minA.setText(str(10.0)) layout.addRow(QLabel('Minimum value of dA for line-fitting: '), self.chi_minA) self.chi_maxA = QLineEdit() self.chi_maxA.setValidator(QDoubleValidator()) self.chi_maxA.setText(str(100.0)) layout.addRow(QLabel('Maximum value of dA for line-fitting: '), self.chi_maxA) self.chi_regress_options.setLayout(layout) lt.addWidget(self.chi_regress_options) self.chi_options.setLayout(lt)
def validating_floatz4_4percent(self): validating_rule = QDoubleValidator(-1, 1, 5) # print(validating_rule.validate(self.Loop.text(), 14)) if validating_rule.validate(self.Z4_4Input.text(), 14)[0] == QValidator.Acceptable: self.Z4_4Input.setFocus() else: self.Z4_4Input.setText("") print('Value for Z(4,-4) needs to be in (-1,1)! This input will be set to 0 if you do not' ' change it.')
def set_validator(self): doubleValitor = QDoubleValidator() doubleValitor.setBottom(-1) doubleValitor.setDecimals(3) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.lineEdit_content.setValidator(doubleValitor) self.lineEdit_water.setValidator(doubleValitor) self.lineEdit_rdensity.setValidator(doubleValitor) self.lineEdit_impurity.setValidator(doubleValitor)
def add_xrange_widget_view(self): """Add widgets below the view combobox to select the x-range applied to view transformation""" hlayout = QHBoxLayout() hlayout.addStretch() #eta self.eta_view = QLineEdit("4") self.eta_view.textChanged.connect(self.change_eta) self.eta_view.setValidator(QDoubleValidator()) self.eta_view.setMaximumWidth(35) self.eta_view.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.eta_label = QLabel("<b>log(eta)</b>") hlayout.addWidget(self.eta_label) hlayout.addWidget(self.eta_view) #space hlayout.addSpacing(5) #xmin self.xmin_view = QLineEdit("-inf") self.xmin_view.textChanged.connect(self.change_xmin) self.xmin_view.setValidator(QDoubleValidator()) self.xmin_view.setMaximumWidth(35) self.xmin_view.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.xmin_label = QLabel("<b>log(t<sub>min</sub>)</b>") hlayout.addWidget(self.xmin_label) hlayout.addWidget(self.xmin_view) #space hlayout.addSpacing(5) #xmax self.xmax_view = QLineEdit("inf") self.xmax_view.textChanged.connect(self.change_xmax) self.xmax_view.setValidator(QDoubleValidator()) self.xmax_view.setMaximumWidth(35) self.xmax_view.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.xmax_label = QLabel(" <b>log(t<sub>max</sub>)</b>") hlayout.addWidget(self.xmax_label) hlayout.addWidget(self.xmax_view) #push button to refresh view self.pb = QPushButton("GO") self.pb.setMaximumWidth(25) self.pb.clicked.connect(self.update_all_ds_plots) hlayout.addWidget(self.pb) self.hlayout_view = hlayout self.ViewDataTheoryLayout.insertLayout(1, self.hlayout_view)
def __init__(self): super().__init__() self.info_label = QLabel( 'The virtual photon source is located at (0, 0) and is 2-D Gaussian spatial ' 'distribution.') self.load_widget = QWidget() self.load_button = QPushButton('Load File') self.load_label = QLabel('Loaded Spatial File:') self.input_group = QGroupBox('Spatial Distributions') self.distribution_widget = QWidget() self.gaussian_button = QRadioButton('Gaussian distribution (FWHM)') self.uniform_button = QRadioButton('Uniform distribution') self.distance_widget = QWidget() self.x_label = QLabel('X (cm) =') self.x_line = QLineEdit() self.y_label = QLabel('Y (cm) =') self.y_line = QLineEdit() self.plot_button = QPushButton('Plot') self.plot_graph = pg.PlotWidget() # self.calc_button = QPushButton('Calculate') self.file_group = QGroupBox('Save new spatial distribution file') self.dir_button = QPushButton('Directory') self.dir_line = QLineEdit() self.name_lable = QLabel('File Name') self.name_line = QLineEdit() self.save_button = QPushButton('Save') # Layouts self.main_layout = QVBoxLayout() self.load_layout = QHBoxLayout() self.input_layout = QVBoxLayout() self.distribution_layout = QHBoxLayout() self.distance_layout = QHBoxLayout() self.file_layout = QGridLayout() self.dir_line.setText(os.getcwd() + '/beam_commissioning/Commissioned_Beams') self.x_line.setValidator(QDoubleValidator(self)) self.y_line.setValidator(QDoubleValidator(self)) self.layout_init() self.pushbutton_init() self.graph_init()
def style_widgets(self): self.density_lbl.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.density_input.setAlignment(Qt.AlignRight) self.density_input.setValidator(QDoubleValidator()) self.density_input.setMaximumWidth(100) self.mass_density.setAlignment(Qt.AlignRight) self.mass_density.setMaximumWidth(100) self.mass_density.setReadOnly(True) self.mass_density.isReadOnly() self.composition_table.setColumnCount(4) self.composition_table.horizontalHeader().setVisible(True) self.composition_table.verticalHeader().setVisible(False) self.composition_table.setContentsMargins(0, 0, 0, 0) self.composition_table.horizontalHeader().setStretchLastSection(False) self.composition_table.setHorizontalHeaderLabels( ['Element', 'Z', 'Charge', 'n']) self.composition_table.horizontalHeaderItem(0).setToolTip( 'Atomic element ') self.composition_table.horizontalHeaderItem(1).setToolTip( 'Atomic number ') self.composition_table.horizontalHeaderItem(2).setToolTip('Charge ') self.composition_table.horizontalHeaderItem(3).setToolTip( 'Proportion of compound ') # Set the alignment to the headers self.composition_table.horizontalHeaderItem(0).setTextAlignment( Qt.AlignLeft) self.composition_table.horizontalHeaderItem(1).setTextAlignment( Qt.AlignHCenter) self.composition_table.horizontalHeaderItem(2).setTextAlignment( Qt.AlignHCenter) self.composition_table.horizontalHeaderItem(3).setTextAlignment( Qt.AlignHCenter) self.composition_table.setColumnWidth(0, 71) self.composition_table.setColumnWidth(1, 66) self.composition_table.setColumnWidth(2, 66) self.composition_table.setColumnWidth(3, 66) self.composition_table.setVerticalScrollBarPolicy( Qt.ScrollBarAlwaysOff) self.composition_table.horizontalHeader().setResizeMode( QHeaderView.Stretch) self.composition_table.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Minimum) self.composition_table.setSizeAdjustPolicy( QAbstractScrollArea.AdjustToContents) self.composition_table.setItemDelegate( utility.ValidatedItemDelegate(self))
def __init__(self): super().__init__(show_automatic_box=True) self.setFixedHeight(310) main_box = gui.widgetBox(self.controlArea, "Fit Initialization", orientation="vertical", width=self.CONTROL_AREA_WIDTH - 10, height=210) button_box = gui.widgetBox(main_box, "", orientation="horizontal", width=self.CONTROL_AREA_WIDTH - 25) gui.button(button_box, self, "Send Fit Initialization", height=40, callback=self.send_fit_initialization) fft_box = gui.widgetBox(main_box, "FFT", orientation="vertical", width=self.CONTROL_AREA_WIDTH - 30) gui.lineEdit(fft_box, self, "s_max", "S_max [nm-1]", labelWidth=250, valueType=float, validator=QDoubleValidator()) self.cb_n_step = orangegui.comboBox( fft_box, self, "n_step", label="FFT Steps", labelWidth=350, items=["1024", "2048", "4096", "8192", "16384", "32768", "65536"], sendSelectedValue=True, orientation="horizontal") orangegui.comboBox(fft_box, self, "fft_type", label="FFT Type", items=FFTTypes.tuple(), orientation="horizontal") orangegui.rubber(self.controlArea) runaction = OWAction("Send Fit Initialization", self) runaction.triggered.connect(self.send_fit_initialization) self.addAction(runaction)
def __init__(self,parent=None): super(lineEditDemo, self).__init__(parent) #创建文本 e1=QLineEdit() #设置文本校验器为整数,只有输入整数才为有效值 e1.setValidator(QIntValidator()) #设置允许输入的最大字符数 e1.setMaxLength(4) #设置文本靠右对齐 e1.setAlignment(Qt.AlignRight) #设置文本的字体和字号大小 e1.setFont(QFont('Arial',20)) #创建文本 e2=QLineEdit() #设置浮点型校验器,有效范围(0.99-99.99),保留两位小数 e2.setValidator(QDoubleValidator(0.99,99.99,2)) #表单布局 flo=QFormLayout() #添加名称及控件到布局中 flo.addRow('integer validator',e1) flo.addRow('Double Validator',e2) #创建文本 e3=QLineEdit() #定义文本输入掩码,9:ASCII字母字符是必须输入的(0-9) e3.setInputMask('+99_9999_999999') flo.addRow('Input Mask',e3) e4=QLineEdit() #文本修改信号发射与槽函数的绑定 e4.textChanged.connect(self.textchanged) flo.addRow('Text changed',e4) e5=QLineEdit() #设置文本框显示的格式,QLineEdit.Password:显示密码掩码字符,而不是实际输入的字符 e5.setEchoMode(QLineEdit.Password) flo.addRow('Password',e5) #创建文本框并增添文本框的内容 e6=QLineEdit('HELLO PyQt5') #设置属性为只读 e6.setReadOnly(True) flo.addRow('Read Only',e6) #编译完成的信号与槽函数的绑定 e5.editingFinished.connect(self.enterPress) #设置窗口的布局 self.setLayout(flo) self.setWindowTitle("QLinedit例子")
def __init__(self, debug=False): super().__init__() self.anaWindows = {} self.w_position = 0 # analysis window position offset self.debug = debug self.raw_signal = None self.Nt = 500 # needs to be set here for initial plot.. self.dt = 1 # .. to create the default signal self.tvec = None # gets initialized by vector_prep self.time_unit = None # gets initialized by qset_time_unit # get updated with dt in -> qset_dt self.periodV = QDoubleValidator(bottom=1e-16, top=1e16) self.envelopeV = QDoubleValidator(bottom=3, top=9999999) self.initUI()
def __init__(self): super().__init__() self.ui = Ui_Isci_ekleWindow() self.ui.setupUi(self) self.ui.txt_TcNo.setValidator(QDoubleValidator()) self.home1 = str(Path.home()) self.home = self.home1 + "/.faceAnalytics/program/worker/" self.UI_Settings() self.sayac = 0 self.show()
def initUI(self): ''' Setup GUI elements of scale window ''' mainLayout = QVBoxLayout() #horizontal layout containing lineedits, unit selector, and label hLayout = QHBoxLayout() self.pixelEdit = LineEdit(str(self.dist_px)) self.pixelEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.pixelEdit.textChanged.connect(self.checkFields) self.scaleEdit = LineEdit(str(self.scale)) self.scaleEdit.setValidator(QDoubleValidator(0.99, 1000.00, 2)) self.scaleEdit.textChanged.connect(self.checkFields) label = QLabel('Pixels:') units = ['km', 'm', 'ft', 'mi'] self.comboBox = QComboBox() self.comboBox.addItems(units) hLayout.addWidget(label) hLayout.addWidget(self.pixelEdit) hLayout.addWidget(self.scaleEdit) hLayout.addWidget(self.comboBox) #horizontal layout containing save and cancel buttons h2Layout = QHBoxLayout() self.saveButton = Button('Save') self.saveButton.clicked.connect(self.save) self.cancelButton = Button('Cancel') self.cancelButton.clicked.connect(self.cancel) h2Layout.addWidget(self.saveButton) h2Layout.addWidget(self.cancelButton) mainLayout.addLayout(hLayout) mainLayout.addLayout(h2Layout) self.setLayout(mainLayout) self.setModal(True) self.show()
def __init__(self, parent=None): # noinspection PyArgumentList super(SoftwareSettingUI, self).__init__(parent) self.setAttribute(Qt.WA_DeleteOnClose) uic.loadUi("ui/ModalSoftwareSettings.ui", self) # Getting the configuration from config.ini file self.config = config.get_config() # Interface self.language_index = int(self.config["SETTINGS"]["software_language"]) self.language.setCurrentIndex(self.language_index) self.language.currentIndexChanged.connect(self.language_alert) # self.default_port.setText( self.config["SETTINGS"]["server_default_port"]) self.socket_timeout.setText( self.config["SETTINGS"]["server_socket_timeout"].replace(".", ",")) self.polling_time.setText( self.config["SETTINGS"]["server_polling_time"].replace(".", ",")) self.connecting_timeout.setText( self.config["SETTINGS"]["connecting_timeout"].replace(".", ",")) self.updating_time.setText( self.config["SETTINGS"]["device_updating_time"].replace(".", ",")) # Obligatory line edit list self.linedit_list = [ self.default_port, self.socket_timeout, self.polling_time, self.updating_time ] # for linedit in self.linedit_list: linedit.textChanged.connect(partial(text_changed, linedit)) # Setting input validation for line edits self.default_port.setValidator(QIntValidator()) self.socket_timeout.setValidator(QDoubleValidator()) self.polling_time.setValidator(QDoubleValidator()) self.connecting_timeout.setValidator(QDoubleValidator()) self.updating_time.setValidator(QDoubleValidator()) # self.apply_button.clicked.connect(self.apply_action) self.cancel_button.clicked.connect(self.close)
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): line_editor = QLineEdit(parent) line_editor.setAlignment(Qt.AlignCenter) double_validator = QDoubleValidator( 0.0, 1.0e9, _MAX_NUM_DIGITS, parent=line_editor ) line_editor.setValidator(double_validator) return line_editor
def __init__(self): super(QLineEditValidatorDemo, self).__init__() self.int_line_edit = QLineEdit() self.double_line_edit = QLineEdit() self.validator_line_edit = QLineEdit() self.int_validator = QIntValidator() self.double_validator = QDoubleValidator() self.reg_validator = QRegExpValidator() self.form_layout = QFormLayout() self.initUI()
def init_validation(self): self.dbleValidator = QDoubleValidator() self.intValidator = QIntValidator() self.xtalMinLineEdit.setValidator(self.dbleValidator) self.xtalMaxLineEdit.setValidator(self.dbleValidator) self.mirrorMinLineEdit.setValidator(self.dbleValidator) self.mirrorMaxLineEdit.setValidator(self.dbleValidator) self.xtalStepsLineEdit.setValidator(self.intValidator) self.mirrorStepsLineEdit.setValidator(self.intValidator) self.undulatorOffsetLineEdit.setValidator(self.dbleValidator)
def initUI(self): grid = QGridLayout() # 使用栅格布局 self.label1 = QLabel('浮点数校验:') # 实例化一个QLabel组件,并将其上文字显示为 '浮点数校验:' grid.addWidget(self.label1, 0, 0) # 放置在第0行、第0列 self.line1 = QLineEdit() grid.addWidget(self.line1, 0, 1) self.line1.setPlaceholderText('浮点类型') # 设置LineEdit未输入时的提示词 self.line1.setValidator(QDoubleValidator()) # 使用浮点校验器(限制只能输入浮点数(包括整数)) self.setLayout(grid) # 将所有以grid栅格布局的控件都显示出来
def __init__(self, initVal=0.0, minVal=None, maxVal=None, decimal=None, textEditCB=None, parent=None): super().__init__(initVal, textEditCB=textEditCB, parent=parent) self.setValidator( QDoubleValidator(float(minVal), float(maxVal), int(decimal)))
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, inputs={'Input': 'default value'}, title='Multi Input Dialog', parent=None): QDialog.__init__(self, parent) self.setWindowTitle(title) self.inputs = inputs self.intValidator = QIntValidator() self.floatValidator = QDoubleValidator() self.createUI()
def loadPositiveIntegerFloat(self, font, src, dst): value = getattr(font.info, src) if value is not None: value = str(value) else: value = "" setattr(self, dst + "Edit", QLineEdit(value, self)) validator = QDoubleValidator(self) validator.setBottom(0) getattr(self, dst + "Edit").setValidator(validator)
def validator_changed(self, index): if index == 0: self.validator_le.setValidator(None) elif index == 1: self.validator_le.setValidator(QIntValidator(-99, 99)) elif index == 2: double_validator = QDoubleValidator(-999.0, 999.0, 2) double_validator.setNotation(QDoubleValidator.StandardNotation) # 0.15 ScientificNotation 1.5*e-2 self.validator_le.setValidator(double_validator) self.validator_le.clear()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.xgm_output_ch_le = SmartStringLineEdit( "SCS_BLU_XGM/XGM/DOOCS:output") self.digitizer_output_ch_le = SmartStringLineEdit( "SCS_UTC1_ADQ/ADC/1:network") self.digitizer_channels = QButtonGroup() self.digitizer_channels.setExclusive(False) for i, ch in enumerate(_DIGITIZER_CHANNEL_NAMES, 1): cb = QCheckBox(ch, self) cb.setChecked(True) self.digitizer_channels.addButton(cb, i - 1) self.mono_device_le = SmartStringLineEdit( "SA3_XTD10_MONO/MDL/PHOTON_ENERGY") self.n_pulses_per_train_le = SmartLineEdit( str(_DEFAULT_N_PULSES_PER_TRAIN)) self.n_pulses_per_train_le.setValidator( QIntValidator(1, config["MAX_N_PULSES_PER_TRAIN"])) self.apd_stride_le = SmartLineEdit("1") self.spectra_displayed = QButtonGroup() self.spectra_displayed.setExclusive(self._MCP_EXCLUSIVE) for i, _ in enumerate(_DIGITIZER_CHANNEL_NAMES, 1): cb = QCheckBox(f"MCP{i}", self) cb.setChecked(True) self.spectra_displayed.addButton(cb, i - 1) self.i0_threshold_le = SmartLineEdit(str(_DEFAULT_I0_THRESHOLD)) self.i0_threshold_le.setValidator(QDoubleValidator()) self.pulse_window_le = SmartLineEdit(str(_MAX_WINDOW)) self.pulse_window_le.setValidator(QIntValidator(1, _MAX_WINDOW)) self.correlation_window_le = SmartLineEdit( str(_MAX_CORRELATION_WINDOW)) self.correlation_window_le.setValidator( QIntValidator(1, _MAX_CORRELATION_WINDOW)) self.n_bins_le = SmartLineEdit(str(_DEFAULT_N_BINS)) self.n_bins_le.setValidator(QIntValidator(1, _MAX_N_BINS)) self._non_reconfigurable_widgets = [ self.xgm_output_ch_le, self.digitizer_output_ch_le, *self.digitizer_channels.buttons(), self.mono_device_le, ] self.initUI() self.initConnections()
def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._filename = None self._page = None self._rect = None self.imageViewer = widgets.imageviewer.ImageViewer() self.dpiLabel = QLabel() self.dpiCombo = QComboBox(insertPolicy=QComboBox.NoInsert, editable=True) self.dpiCombo.lineEdit().setCompleter(None) self.dpiCombo.setValidator(QDoubleValidator(10.0, 1200.0, 4, self.dpiCombo)) self.dpiCombo.addItems([format(i) for i in (72, 100, 200, 300, 600, 1200)]) self.colorButton = widgets.colorbutton.ColorButton() self.colorButton.setColor(QColor(Qt.white)) self.crop = QCheckBox() self.antialias = QCheckBox(checked=True) self.scaleup = QCheckBox(checked=False) self.dragfile = QPushButton(icons.get("image-x-generic"), None, None) self.fileDragger = FileDragger(self.dragfile) self.buttons = QDialogButtonBox(QDialogButtonBox.Close) self.copyButton = self.buttons.addButton('', QDialogButtonBox.ApplyRole) self.copyButton.setIcon(icons.get('edit-copy')) self.saveButton = self.buttons.addButton('', QDialogButtonBox.ApplyRole) self.saveButton.setIcon(icons.get('document-save')) layout = QVBoxLayout() self.setLayout(layout) layout.addWidget(self.imageViewer) controls = QHBoxLayout() layout.addLayout(controls) controls.addWidget(self.dpiLabel) controls.addWidget(self.dpiCombo) controls.addWidget(self.colorButton) controls.addWidget(self.crop) controls.addWidget(self.antialias) controls.addWidget(self.scaleup) controls.addStretch() controls.addWidget(self.dragfile) layout.addWidget(widgets.Separator()) layout.addWidget(self.buttons) app.translateUI(self) self.readSettings() self.finished.connect(self.writeSettings) self.dpiCombo.editTextChanged.connect(self.drawImage) self.colorButton.colorChanged.connect(self.drawImage) self.antialias.toggled.connect(self.drawImage) self.scaleup.toggled.connect(self.drawImage) self.crop.toggled.connect(self.cropImage) self.buttons.rejected.connect(self.reject) self.copyButton.clicked.connect(self.copyToClipboard) self.saveButton.clicked.connect(self.saveAs) qutil.saveDialogSize(self, "copy_image/dialog/size", QSize(480, 320))
def __init__(self, controller, *args, **kwargs): super().__init__(*args, **kwargs) self.controller = controller self.min = float() self.val = float() self.max = float() layout = QGridLayout() edit_group = QGroupBox() edits = QGridLayout() edits.addWidget(QLabel("Input name"), 0, 0) self.var_name = QLineEdit() edits.addWidget(self.var_name, 0, 1) self.var_min = QLineEdit() self.var_min.setValidator(QDoubleValidator()) edits.addWidget(QLabel("Min"), 1, 0) edits.addWidget(self.var_min, 1, 1) self.var_max = QLineEdit() self.var_max.setValidator(QDoubleValidator()) edits.addWidget(QLabel("Max"), 2, 0) edits.addWidget(self.var_max, 2, 1) self.var_val = QLineEdit() self.var_val.setValidator(QDoubleValidator()) edits.addWidget(QLabel("Val"), 3, 0) edits.addWidget(self.var_val, 3, 1) edit_group.setLayout(edits) layout.addWidget(edit_group, 0, 0) button_layout = QHBoxLayout() accept_button = QPushButton("Accept") accept_button.clicked.connect(self.verify) button_layout.addWidget(accept_button) cancel_button = QPushButton("Cancel") cancel_button.clicked.connect(self.reject) button_layout.addWidget(cancel_button) layout.addLayout(button_layout, 1, 0) self.setLayout(layout)
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex) -> QWidget: wdgt = QLineEdit(parent) wdgt.setAttribute(Qt.WA_InputMethodEnabled, False) if self.__ValueType == JPFieldType.Int: wdgt.setValidator(QIntValidator()) if self.__ValueType == JPFieldType.Float: va = QDoubleValidator() va.setDecimals(self.__Decimal) wdgt.setValidator(va) return wdgt
def set_validator(self): if self.element.attribute("NumbersOnly") != "1": return doubleValitor = QDoubleValidator() if is_float(self.element.attribute("Min")): doubleValitor.setBottom((self.element.attribute("Min"))) if is_float(self.element.attribute("Max")): doubleValitor.setTop(float(self.element.attribute("Max"))) # doubleValitor.setDecimals(2) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.setValidator(doubleValitor)