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


Python QtGui.QValidator方法代码示例

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


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

示例1: validate

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QValidator [as 别名]
def validate(self, string, index):
        # one approach is to break the string into segments
        # and test each segment for proper content
        state = qtg.QValidator.Acceptable
        seg1 = string[0:2]
        dash1 = string[2:3]
        seg2 = string[3:6]
        dash2 = string[6:7]
        seg3 = string[7:11]
        seg4 = string[11:12]

        if not all([char in self.valid_letters for char in seg1 + seg4]):
            state = qtg.QValidator.Invalid
        elif not all([char.isdigit() for char in seg2 + seg3]):
            state = qtg.QValidator.Invalid
        elif not all([char == '-' for char in dash1 + dash2]):
            state = qtg.QValidator.Invalid
        elif len(string) > 12:
            state = qtg.QValidator.Invalid
        elif not all([seg1, dash1, seg2, dash2, seg3, seg4]):
            state = qtg.QValidator.Intermediate

        return (state, string, index) 
开发者ID:PacktPublishing,项目名称:Mastering-GUI-Programming-with-Python,代码行数:25,代码来源:inventory_validator.py

示例2: validate

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QValidator [as 别名]
def validate(self, original, offset):  # pylint:disable=W0613
            """Fixes original text and resets cursor to end of line."""

            filtered = self.fixup(original)
            return QtGui.QValidator.Acceptable, filtered, len(filtered) 
开发者ID:AwesomeTTS,项目名称:awesometts-anki-addon,代码行数:7,代码来源:configurator.py

示例3: validate

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QValidator [as 别名]
def validate(self, string, index):
        if string in self.choices:
            state = qtg.QValidator.Acceptable
        elif any([v.startswith(string) for v in self.choices]):
            state = qtg.QValidator.Intermediate
        else:
            state = qtg.QValidator.Invalid
        return (state, string, index) 
开发者ID:PacktPublishing,项目名称:Mastering-GUI-Programming-with-Python,代码行数:10,代码来源:widget_demo.py

示例4: select_type_validator

# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QValidator [as 别名]
def select_type_validator(tp: click.types.ParamType)-> QtGui.QValidator:
    """ select the right validator for `tp`"""
    if isinstance(tp, click.types.IntParamType):
        return QtGui.QIntValidator()
    elif isinstance(tp, click.types.FloatParamType):
        return QtGui.QDoubleValidator()
    return None 
开发者ID:szsdk,项目名称:quick,代码行数:9,代码来源:quick.py


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