Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: How do I set a QLineEdit's validator in the designer?

Tags:

c++

qt

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.

like image 504
Cornstalks Avatar asked Aug 16 '12 19:08

Cornstalks


People also ask

How do I create a text box in Qt?

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.

What is QLineEdit?

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.

How do I hide line edits in Qt?

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.

How can I hide my QT password?

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.


1 Answers

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.

like image 67
Eric Hulser Avatar answered Sep 19 '22 07:09

Eric Hulser