当前位置: 首页>>代码示例>>Python>>正文


Python QRegExp.setPattern方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QRegExp.setPattern方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.setPattern方法的具体用法?Python QRegExp.setPattern怎么用?Python QRegExp.setPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QRegExp的用法示例。


在下文中一共展示了QRegExp.setPattern方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HistoryCompletionModel

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPattern [as 别名]
class HistoryCompletionModel(QSortFilterProxyModel):
    """
    Class implementing a special model for history based completions.
    """
    HistoryCompletionRole = HistoryFilterModel.MaxRole + 1
    
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent object (QObject)
        """
        super(HistoryCompletionModel, self).__init__(parent)
        
        self.__searchString = ""
        self.__searchMatcher = QRegExp(
            "", Qt.CaseInsensitive, QRegExp.FixedString)
        self.__wordMatcher = QRegExp("", Qt.CaseInsensitive)
        self.__isValid = False
        
        self.setDynamicSortFilter(True)
    
    def data(self, index, role=Qt.DisplayRole):
        """
        Public method to get data from the model.
        
        @param index index of history entry to get data for (QModelIndex)
        @param role data role (integer)
        @return history entry data
        """
        # If the model is valid, tell QCompleter that everything we have
        # filtered matches what the user typed; if not, nothing matches
        if role == self.HistoryCompletionRole and index.isValid():
            if self.isValid():
                return "t"
            else:
                return "f"
        
        if role == Qt.DisplayRole:
            if index.column() == 0:
                role = HistoryModel.UrlStringRole
            else:
                role = HistoryModel.TitleRole
        
        return QSortFilterProxyModel.data(self, index, role)
    
    def searchString(self):
        """
        Public method to get the current search string.
        
        @return current search string (string)
        """
        return self.__searchString
    
    def setSearchString(self, string):
        """
        Public method to set the current search string.
        
        @param string new search string (string)
        """
        if string == self.__searchString:
            return
        
        self.__searchString = string
        self.__searchMatcher.setPattern(self.__searchString)
        self.__wordMatcher.setPattern(
            "\\b" + QRegExp.escape(self.__searchString))
        self.invalidateFilter()
    
    def isValid(self):
        """
        Public method to check the model for validity.
        
        @return flag indicating a valid status (boolean)
        """
        return self.__isValid
    
    def setValid(self, valid):
        """
        Public method to set the model's validity.
        
        @param valid flag indicating the new valid status (boolean)
        """
        if valid == self.__isValid:
            return
        
        self.__isValid = valid
        
        # tell the history completer that the model has changed
        self.dataChanged.emit(self.index(0, 0), self.index(0,
                              self.rowCount() - 1))
    
    def filterAcceptsRow(self, sourceRow, sourceParent):
        """
        Public method to determine, if the row is acceptable.
        
        @param sourceRow row number in the source model (integer)
        @param sourceParent index of the source item (QModelIndex)
        @return flag indicating acceptance (boolean)
        """
#.........这里部分代码省略.........
开发者ID:pycom,项目名称:EricShort,代码行数:103,代码来源:HistoryCompleter.py

示例2: VariantDelegate

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPattern [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))
#.........这里部分代码省略.........
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:103,代码来源:settingseditor.py


注:本文中的PyQt5.QtCore.QRegExp.setPattern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。