May 2019
Intermediate to advanced
542 pages
13h 37m
English
To demonstrate widget validation, let's create a widget that validates Internet Protocol version 4 (IPv4) addresses. An IPv4 address must be in the format of 4 integers, each between 0 and 255, with a dot between each number.
Let's start by creating our validator class. Add this class just before the MainWindow class:
class IPv4Validator(qtg.QValidator): """Enforce entry of IPv4 Addresses"""
Next, we need to override this class's validate() method. validate() receives two pieces of information: a string that contains the proposed input and the index at which the input occurred. It will have to return a value that indicates whether the input is Acceptable, Intermediate, or Invalid. If the input is acceptable or ...
Read now
Unlock full access