本文整理汇总了Python中PyQt5.QtCore.QRegExp.pattern方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.pattern方法的具体用法?Python QRegExp.pattern怎么用?Python QRegExp.pattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.pattern方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VariantDelegate
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pattern [as 别名]
class VariantDelegate(QItemDelegate):
def __init__(self, parent=None):
super(VariantDelegate, self).__init__(parent)
self.boolExp = QRegExp()
self.boolExp.setPattern('true|false')
self.boolExp.setCaseSensitivity(Qt.CaseInsensitive)
self.byteArrayExp = QRegExp()
self.byteArrayExp.setPattern('[\\x00-\\xff]*')
self.charExp = QRegExp()
self.charExp.setPattern('.')
self.colorExp = QRegExp()
self.colorExp.setPattern('\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)')
self.doubleExp = QRegExp()
self.doubleExp.setPattern('')
self.pointExp = QRegExp()
self.pointExp.setPattern('\\((-?[0-9]*),(-?[0-9]*)\\)')
self.rectExp = QRegExp()
self.rectExp.setPattern('\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)')
self.signedIntegerExp = QRegExp()
self.signedIntegerExp.setPattern('-?[0-9]*')
self.sizeExp = QRegExp(self.pointExp)
self.unsignedIntegerExp = QRegExp()
self.unsignedIntegerExp.setPattern('[0-9]*')
self.dateExp = QRegExp()
self.dateExp.setPattern('([0-9]{,4})-([0-9]{,2})-([0-9]{,2})')
self.timeExp = QRegExp()
self.timeExp.setPattern('([0-9]{,2}):([0-9]{,2}):([0-9]{,2})')
self.dateTimeExp = QRegExp()
self.dateTimeExp.setPattern(self.dateExp.pattern() + 'T' + self.timeExp.pattern())
def paint(self, painter, option, index):
if index.column() == 2:
value = index.model().data(index, Qt.UserRole)
if not self.isSupportedType(value):
myOption = QStyleOptionViewItem(option)
myOption.state &= ~QStyle.State_Enabled
super(VariantDelegate, self).paint(painter, myOption, index)
return
super(VariantDelegate, self).paint(painter, option, index)
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
def setEditorData(self, editor, index):
value = index.model().data(index, Qt.UserRole)
if editor is not None:
editor.setText(self.displayText(value))
#.........这里部分代码省略.........