Apply a validator (subclass of QValidator) on the widget and make sure its fixup() method is implemented correctly. This should do the trick.