當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。