Python PyQt5.QtGui 模块,QRegExpValidator() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用PyQt5.QtGui.QRegExpValidator()

项目:pbtk    作者:marin-m    | 项目源码 | 文件源码
def __init__(self, min_, max_, float_=False):
        super(QwordSpinBox, self).__init__()

        self._minimum = min_
        self._maximum = max_
        self.int_ = float if float_ else int

        rx = QRegExp('-?\d{0,20}(?:\.\d{0,20})?' if float_ else '-?\d{0,20}')
        validator = QRegExpValidator(rx, self)

        self._lineEdit = QLineEdit(self)
        self._lineEdit.setText(str(self.int_(0)))
        self._lineEdit.setValidator(validator)
        self._lineEdit.textEdited.connect(partial(self.setValue, change=False))
        self.editingFinished.connect(lambda: self.setValue(self.value(), update=False) or True)
        self.setLineEdit(self._lineEdit)
项目:EMFT    作者:132nd-etcher    | 项目源码 | 文件源码
def __init__(
        self,
        text,
        on_text_changed: callable = None,
        read_only: bool = False,
        clear_btn_enabled: bool = False,
        validation_regex: str = None,
        set_enabled: bool = True,
    ):
        QLineEdit.__init__(self, text)
        if on_text_changed:
            # noinspection PyUnresolvedReferences
            self.textChanged.connect(on_text_changed)
        self.setReadOnly(read_only)
        self.setClearButtonEnabled(clear_btn_enabled)
        if validation_regex:
            self.setValidator(QRegExpValidator(QRegExp(validation_regex), self))
        self.setEnabled(set_enabled)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def __init__(self, checksum_label: ChecksumLabel, message: Message, proto_view: int, parent=None):
        super().__init__(parent)
        self.ui = Ui_ChecksumOptions()
        self.ui.setupUi(self)
        self.checksum_label = checksum_label
        self.data_range_table_model = self.RangeTableModel(checksum_label, message, proto_view, parent=self)
        self.ui.tableViewDataRanges.setItemDelegateForColumn(0, SpinBoxDelegate(1, 999999, self))
        self.ui.tableViewDataRanges.setItemDelegateForColumn(1, SpinBoxDelegate(1, 999999, self))
        self.ui.tableViewDataRanges.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.ui.tableViewDataRanges.setModel(self.data_range_table_model)
        self.ui.tableViewDataRanges.setEditTriggers(QAbstractItemView.AllEditTriggers)
        self.display_crc_data_ranges_in_table()
        self.ui.comboBoxCRCFunction.addItems([crc_name for crc_name in GenericCRC.DEFAULT_POLYNOMIALS])
        self.ui.comboBoxCRCFunction.addItems([special_crc_name for special_crc_name in self.SPECIAL_CRCS])
        self.ui.lineEditCRCPolynomial.setValidator(QRegExpValidator(QRegExp("[0-9,a-f]*")))
        self.ui.comboBoxCategory.clear()
        for _, member in self.checksum_label.Category.__members__.items():
            self.ui.comboBoxCategory.addItem(member.value)
        self.set_ui_for_category()
        self.setFocus()
        self.create_connects()
项目:EMFT    作者:132nd-etcher    | 项目源码 | 文件源码
def createEditor(self, parent: QWidget, style: QStyleOptionViewItem, index: QModelIndex):  # noqa: N802
            editor = QLineEdit(parent)
            if self._regex:
                validator = QRegExpValidator(editor)
                validator.setRegExp(QRegExp(self._regex))
                editor.setValidator(validator)
            editor.setText(str(index.data(Qt.DisplayRole)))
            return editor
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, parent = None):
        QDoubleSpinBox.__init__(self, parent)
        self.saved_suffix = ''
        #Let's use the locale decimal separator if it is different from the dot ('.')
        local_decimal_separator = QLocale().decimalPoint()
        if local_decimal_separator == '.':
            local_decimal_separator = ''
        self.lineEdit().setValidator(QRegExpValidator(QRegExp("-?[0-9]*[.{0}]?[0-9]*.*".format(local_decimal_separator)), self))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def createEditor(self, parent, option, index):
        if index.column() != 2:
            return None

        originalValue = index.model().data(index, Qt.UserRole)
        if not self.isSupportedType(originalValue):
            return None

        lineEdit = QLineEdit(parent)
        lineEdit.setFrame(False)

        if isinstance(originalValue, bool):
            regExp = self.boolExp
        elif isinstance(originalValue, float):
            regExp = self.doubleExp
        elif isinstance(originalValue, int):
            regExp = self.signedIntegerExp
        elif isinstance(originalValue, QByteArray):
            regExp = self.byteArrayExp
        elif isinstance(originalValue, QColor):
            regExp = self.colorExp
        elif isinstance(originalValue, QDate):
            regExp = self.dateExp
        elif isinstance(originalValue, QDateTime):
            regExp = self.dateTimeExp
        elif isinstance(originalValue, QTime):
            regExp = self.timeExp
        elif isinstance(originalValue, QPoint):
            regExp = self.pointExp
        elif isinstance(originalValue, QRect):
            regExp = self.rectExp
        elif isinstance(originalValue, QSize):
            regExp = self.sizeExp
        else:
            regExp = QRegExp()

        if not regExp.isEmpty():
            validator = QRegExpValidator(regExp, lineEdit)
            lineEdit.setValidator(validator)

        return lineEdit
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def createEditor(self, parent, option, index):
        if index.column() != 2:
            return None

        originalValue = index.model().data(index, Qt.UserRole)
        if not self.isSupportedType(originalValue):
            return None

        lineEdit = QLineEdit(parent)
        lineEdit.setFrame(False)

        if isinstance(originalValue, bool):
            regExp = self.boolExp
        elif isinstance(originalValue, float):
            regExp = self.doubleExp
        elif isinstance(originalValue, int):
            regExp = self.signedIntegerExp
        elif isinstance(originalValue, QByteArray):
            regExp = self.byteArrayExp
        elif isinstance(originalValue, QColor):
            regExp = self.colorExp
        elif isinstance(originalValue, QDate):
            regExp = self.dateExp
        elif isinstance(originalValue, QDateTime):
            regExp = self.dateTimeExp
        elif isinstance(originalValue, QTime):
            regExp = self.timeExp
        elif isinstance(originalValue, QPoint):
            regExp = self.pointExp
        elif isinstance(originalValue, QRect):
            regExp = self.rectExp
        elif isinstance(originalValue, QSize):
            regExp = self.sizeExp
        else:
            regExp = QRegExp()

        if not regExp.isEmpty():
            validator = QRegExpValidator(regExp, lineEdit)
            lineEdit.setValidator(validator)

        return lineEdit
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def set_allow_negative(self, allow):
        self._allow_negative = allow
        if allow:
            self.setInputMask('X9:99:99.999')
            self.setValidator(
                QtGui.QRegExpValidator(
                    QtCore.QRegExp(r'[+-]\d:\d\d:\d\d\.\d\d\d'),
                    self.parent()))
        else:
            self.setInputMask('9:99:99.999')
        self.reset_text()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def createEditor(self, parent, option, index):
        if index.column() != 2:
            return None

        originalValue = index.model().data(index, Qt.UserRole)
        if not self.isSupportedType(originalValue):
            return None

        lineEdit = QLineEdit(parent)
        lineEdit.setFrame(False)

        if isinstance(originalValue, bool):
            regExp = self.boolExp
        elif isinstance(originalValue, float):
            regExp = self.doubleExp
        elif isinstance(originalValue, int):
            regExp = self.signedIntegerExp
        elif isinstance(originalValue, QByteArray):
            regExp = self.byteArrayExp
        elif isinstance(originalValue, QColor):
            regExp = self.colorExp
        elif isinstance(originalValue, QDate):
            regExp = self.dateExp
        elif isinstance(originalValue, QDateTime):
            regExp = self.dateTimeExp
        elif isinstance(originalValue, QTime):
            regExp = self.timeExp
        elif isinstance(originalValue, QPoint):
            regExp = self.pointExp
        elif isinstance(originalValue, QRect):
            regExp = self.rectExp
        elif isinstance(originalValue, QSize):
            regExp = self.sizeExp
        else:
            regExp = QRegExp()

        if not regExp.isEmpty():
            validator = QRegExpValidator(regExp, lineEdit)
            lineEdit.setValidator(validator)

        return lineEdit
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def __init__(self):
        super(addcontact_class, self).__init__()
        self.setupUi(self)


        regex_name = QtCore.QRegExp("[a-z-A-Z_]+")
        name_validator = QtGui.QRegExpValidator(regex_name)
        self.name_lineEdit.setValidator(name_validator)
        #self.name_lineEdit = str(self.name_lineEdit.text())


        self.phone_lineEdit.setMaxLength(10)
        regex_phone = QtCore.QRegExp("[0-9_]+")
        phone_validator = QtGui.QRegExpValidator(regex_phone)
        self.phone_lineEdit.setValidator(phone_validator)


        regex_email = QtCore.QRegExp('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$')
        email_validator = QtGui.QRegExpValidator(regex_email)
        self.email_lineEdit.setValidator(email_validator)
        #self.email_lineEdit = str(self.email_lineEdit)


        #self.address_textEdit = str(self.address_textEdit)


        self.dob_dateEdit.setDisplayFormat('dd-MM-yyyy')
        #self.dob_dateEdit.setCalendarPopup(True)
        self.dob_dateEdit.setDate(QtCore.QDate.currentDate())
        temp_dob = self.dob_dateEdit.date()
        # DOB = temp_dob.toPyDate()
        DOB =temp_dob.toString('dd/MM/yyyy')
        print(DOB)









        self.btn_set_icon.clicked.connect(self.openFileNameDialog)
        self.btn_save.clicked.connect(self.save_action)
项目:VIRTUAL-PHONE    作者:SumanKanrar-IEM    | 项目源码 | 文件源码
def __init__(self):
        super(addcontact_class, self).__init__()
        self.setupUi(self)


        regex_name = QtCore.QRegExp("[a-z-A-Z_]+")
        name_validator = QtGui.QRegExpValidator(regex_name)
        self.name_lineEdit.setValidator(name_validator)
        #self.name_lineEdit = str(self.name_lineEdit.text())


        self.phone_lineEdit.setMaxLength(10)
        regex_phone = QtCore.QRegExp("[0-9_]+")
        phone_validator = QtGui.QRegExpValidator(regex_phone)
        self.phone_lineEdit.setValidator(phone_validator)


        regex_email = QtCore.QRegExp('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$')
        email_validator = QtGui.QRegExpValidator(regex_email)
        self.email_lineEdit.setValidator(email_validator)
        #self.email_lineEdit = str(self.email_lineEdit)


        #self.address_textEdit = str(self.address_textEdit)


        self.dob_dateEdit.setDisplayFormat('dd-MM-yyyy')
        #self.dob_dateEdit.setCalendarPopup(True)
        self.dob_dateEdit.setDate(QtCore.QDate.currentDate())
        temp_dob = self.dob_dateEdit.date()
        # DOB = temp_dob.toPyDate()
        DOB =temp_dob.toString('dd/MM/yyyy')
        print(DOB)









        self.btn_set_icon.clicked.connect(self.openFileNameDialog)
        self.btn_save.clicked.connect(self.save_action)