Skip to content

WhitelistValidator

Qt Base Class: QValidator

Signature: QValidator(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
Validator
prettyqt.gui.validator

Subclasses

Class Module Description
EmptyValidator prettyqt.validators.whitelistvalidator

⋔ Inheritance diagram

graph TD
  1473367032576["validators.WhitelistValidator"]
  1473245568976["gui.Validator"]
  1473245536768["gui.ValidatorMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289208592["QtGui.QValidator"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473245568976 --> 1473367032576
  1473245536768 --> 1473245568976
  1473299815024 --> 1473245536768
  140713234304496 --> 1473299815024
  1473289208592 --> 1473245568976
  1473288842240 --> 1473289208592
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: Validator

Validator which allows a fixed list of strings.

Source code in prettyqt\validators\whitelistvalidator.py
class WhitelistValidator(gui.Validator):
    """Validator which allows a fixed list of strings."""

    ID = "whitelist"

    def __init__(
        self,
        options: list[str] | None = None,
        parent: QtCore.QObject | None = None,
    ):
        super().__init__(parent)
        self._options = options

    def __eq__(self, other: object):
        return isinstance(other, WhitelistValidator) and self._options == other._options

    def validate(self, text: str, pos: int = 0):
        if any(option == text for option in self._options):
            return self.State.Acceptable, text, pos
        if any(option.startswith(text) for option in self._options):
            return self.State.Intermediate, text, pos
        return self.State.Invalid, text, pos

⌗ Property table

Qt Property Type Doc
objectName QString

Validator ID: whitelist