I'm designing a UI at the moment, and I have a situation where I have a QLineEdit which I need to only accept integers.
I know how to set the validator to use QIntValidator in code. But I'd like to do this in the designer.
How can I set the QLineEdit's validator when using the designer?
Note: I don't want to use an input mask. An input mask and a validator function differently.
You can use the Text Edit and Text Input components to add text fields where users can enter text. The Text Input component displays a single line of editable plain text, whereas the Text Edit component displays a block of editable, formatted text. Both components are used to accept text input.
The QLineEdit widget is a one-line text editor. A line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.
You can disable QLineEdit using method "setEnabled ( false )":http://qt-project.org/doc/qt-4.8/qwidget.html#enabled-prop which is inherited from QWidget.
Qt QLinEdit fields can be toggled to hide input using the . setEchoMode method, passing in the constant QtWidgets. QLineEdit. Password to hide all input or QtWidgets.
Are you asking how to do it 100% through designer, or for a widget that was designed in designer?
You're going to need to do it at the code level no matter what, there is no way to do it directly in designer - not all functionality is exposed to it.
Out of curiosity, why not use a QSpinBox if you're getting purely an integer? You could use a QSpinBox and set the buttonSymbols to NoButtons, and even specify a suffix & prefix of text if you want. The end result looks and acts almost exactly like a QLineEdit, however is geared specifically for integer values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With