OK, this is driving me nuts. I'm sure it is trivial, but I've been looking for the answer for a while and don't see it. I'm sure it will be a flat forehead.
I'm designing a Qt4 dialog in Python. I generated the code via QDesigner, and have 4 inputs on the system:
- QLineEdit (can't be blank)
- QPlainTextEdit
- QLineEdit (can't be blank)
- QComboBox (need to select one of the options)
Question: Is there a flag which makes a field "required"? Forces it to be non-blank?
I was trying to use a QRegExpValidator, but not sure this is right:
regex = QRegExp(r"\\S+")
self.optionName.setValidator(QRegExpValidator(regex,self))
I know I'm missing something obvious (please, don't let it be a self.optionName.setRequired() function).
Update
I've now added this class:
from PyQt4 import QtGui
class ValidStringLength(QtGui.QValidator):
def __init__(self, min, max, parent):
QtGui.QValidator.__init__(self, parent)
self.min = min
self.max = max
def validate(self, s, pos):
if self.max > -1 and len(s) > self.max:
return (QValidator.Invalid, pos)
if self.min > -1 and len(s) < self.min:
return (QValidator.Intermediate, pos)
return (QValidator.Acceptable, pos)
def fixup(self, s):
pass
Call it like this:
self.optionName.setValidator(ValidStringLength(2, 8, self.optionName))
self.criteriaName.setValidator(ValidStringLength(2, 8, self.criteriaName))
and have a breakpoint set at the validate() function of the class, but that is never called.
Am I missing something basic?
TIA
Mike