The QValidator class provides validation of input text. The class itself is abstract. Two subclasses, QIntValidator and QDoubleValidator, provide basic numeric-range checking, and QRegExpValidator provides general checking using a custom regular expression. If the built-in validators aren't sufficient, you can subclass QValidator.
Questions tagged [qvalidator]
30 questions
11
votes
1 answer
QLineEdit with QValidator: React to editing finished regardless of input validity?
QLineEdit has a signal QLineEdit::editingFinished that gets emitted when the user finished editing, for example by pressing enter. However if a validator or an input mask was set, then editingFinished only gets emitted if the input is valid.
But how…

Stefan Pfeifer
- 593
- 6
- 16
11
votes
2 answers
Validating user input in a QTableView
I have a QTableView and I want to validate user input.
If user insert an invalid value in a cell of the QTableView, I want to highlight that cell and disable a QPushButton.
How can I achieve this? Can I use QValidator?

splunk
- 6,435
- 17
- 58
- 105
8
votes
7 answers
QDoubleValidator is not working?
I'm trying to apply validator in a line edit box in Qt 4.2 and it is not working:
QDoubleValidator *haha= new QDoubleValidator(this);
haha->setBottom(0.00);
haha->setDecimals(2);
haha->setTop(100.00);
get_line_edit()->setValidator(haha);
or
…

user987013
- 233
- 2
- 6
- 18
6
votes
3 answers
Get visual feedback from QValidator
I am trying to use QValidator descendants (actually in PyQt5, but that shouldn't matter) to validate a series of line-edits.
A small excerpt is:
class IPv4(QWidget):
def __init__(self):
super(IPv4, self).__init__()
…

ZioByte
- 2,690
- 1
- 32
- 68
3
votes
1 answer
Programmatically validate a QLineEdit
I have a QLineEdit with a QDoubleValidator, calling QDoubleValidator::setRange will not validate the current text of the QLineEdit.
How could I programmatically validate (focusing and unfocusing it with the mouse work )
Here is the code of my…

Mathieu Westphal
- 2,544
- 1
- 19
- 33
2
votes
1 answer
Validate if editable QCombobox input is a directory via QValidator
I try to validate if a editable QCombobox input is a directory or not before it gets added to the QCombobox.
from PySide import QtGui, QtCore
class DirValidator(QtGui.QValidator):
def __init__(self, cb_input):
super(DirValidator,…

zwusel
- 171
- 12
2
votes
1 answer
Proper usage of QValidator
I use validators to filter user input. Normally I have my validators working like this:
my_reg_ex = QRegExp("[1-9]\d{0,5}")
my_validator = QRegExpValidator(my_reg_ex, self.ui.lineEdit_test)
self.ui.lineEdit_test.setValidator(my_validator)
I wrote…

shafuq
- 465
- 6
- 20
2
votes
2 answers
Recognize if a QLineEdit loses a focus
In one of my projects I have a series of QLineEdit Widgets, that should accept double numbers, that are lying in a certain range. For certain reasons I can not use QDoubleSpinBox.
Now I'm using QDoubleValidator to check, if my number lies in the…

Aleph0
- 5,816
- 4
- 29
- 80
2
votes
2 answers
QDoubleValidator accepts multiple decimal points
I'm using a QDoubleValidator for my QLineEdit. The application locale (set in QtCreator) is QLocale::German.
Now when I enter a valid double (either using a dot or a comma as decimal separator) writing to the textedit as well as converting the…

Uroc327
- 1,379
- 2
- 10
- 28
2
votes
1 answer
Get text prior to edit from inside QLineEdit::textEdited()
When I receive a QLineEdit::textEdited() signal, can I see what the text was prior to the edit? I need to compare the text as it was prior to the edit and the text after the edit.
The textEdited() signal has only one argument, which is the new text.…

sashoalm
- 75,001
- 122
- 434
- 781
1
vote
1 answer
Using QDoubleValidator to limit QLineEdit input and reset the value to nearest acceptable
I would like to use QLineEdit to get user input for values. I want to limit the input between a range so I should use QDoubleValidator. I would like it to work such that if they go over the allowed value, it sets the text to the top() value and if…

Amanda.py
- 113
- 10
1
vote
1 answer
PyQT5: How to use both QLineEdit: Validator and InputMask?
I want to use both InputMask and Validator to get date in the correct form. In the code below I am using InputMask to receive date in format DD.MM.YYYY. I do not know how to limit each part of it (DD, MM and YYYY) because now user can type…

Julia Szymik
- 23
- 4
1
vote
1 answer
PyQt5 cannot get function and classes right
Hi need help about why is not working think is conceptual but I cannot grasp it.
I have some files:
main.py :
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 14:25:12 2020
@author: Pietro
"""
import sys
from PyQt5 import…

pippo1980
- 2,181
- 3
- 14
- 30
1
vote
0 answers
QIntValidator's 'bottom' property is not being actioned at the user input stage
I'm new to PyQt5 and trying to implement some code in Python and PyQt5 to validate a QLineEdit field's user input.
The QIntValidator 'bottom' integer value is set to 100 and the 'top' to 200. When inputting data to the field, values over 200 can't…

tjm_777
- 11
- 2
1
vote
1 answer
Passing line-edits to a contextmanager to set validators
I am trying to pass a list of widgets into ca ontextmanager in which I am trying to set them with QDoubleValidators.
My initial code is something as follows:
validator =…

Teh Ki
- 455
- 1
- 3
- 14