Reputation: 11
I'm trying to override fixup in QIntValidator for PyQt6. I have verified that the subclass is being applied by looking at the appropriate object in a watch table. However, behaviors that I put into fixup() do not execute. It seems as though the core QIntValidator fixup() is working because if I try to type a letter into the applicable field, no text can be entered. Numbers can be entered, however, just as you'd expect from a QIntValidator fixup() call. Right now, I'm just putting a simple print command in, but I have tried several other behaviors and none of them have worked.
I have already worked around this by modifying the slot connected to the text input signal, but I'd like to know the "correct" way to do this using the validator since that can be inherited by any instantiations.
Here is my watch table showing that the correct parent classes for my two validation schemes: enter image description here
Here is the StepsInput subclass:
from IntValidator import IntValidator
from LabeledInputInput import LabeledInputInput
class StepsInput(LabeledInputInput):
def set_validator(self)-> None:
validator = IntValidator(1, 255)
self.setValidator(validator)
return
Here is the IntValidator subclass
from PyQt6.QtGui import QIntValidator
class IntValidator(QIntValidator):
def fixup(self, input):
input = "123"
return input
Here is the LabeledInputInput parent class:
from PyQt6.QtWidgets import QLineEdit
from PyQt6.QtCore import Qt, QRegularExpression
from PyQt6.QtGui import QRegularExpressionValidator
from PasteToMenu import PasteToMenu
class LabeledInputInput(QLineEdit):
context_menu: PasteToMenu
def __init__(self):
super().__init__()
self.context_menu = PasteToMenu()
self.__set_appearance()
self.set_validator()
return
def contextMenuEvent(self, event):
self.context_menu.exec(event.globalPos())
return
def __set_appearance(self)-> None:
self.setFixedSize(50, 20)
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setStyleSheet(self.__generate_style_sheet())
return
def __generate_style_sheet(self)-> str:
return '''
LabeledInputInput {
background-color: #EEEEEE;
border: 2px solid #FFD369;
color: #393E46;
font-size: 10pt;
font-weight: bold;
}
'''
def set_validator(self)-> None:
pattern = '[0-9]+'
regex = QRegularExpression(pattern)
validator = QRegularExpressionValidator(regex)
self.setValidator(validator)
return
Upvotes: 1
Views: 390