简体   繁体   中英

Understanding the behaviour of QDoubleValidator range

The specification of the options 'top' and 'bottom' seems to have a strange behavior. The following answered question gave some useful insights, but does not cure everything.

With the code:

import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

app = QApplication(sys.argv)

input = QLineEdit()
input.setValidator(QDoubleValidator(0.00,10.00,5,notation=QDoubleValidator.StandardNotation))

input.show()
sys.exit(app.exec_())

The input box accepts any number below 100, but I would expect only numbers below 10... For example, 99.55656 is accepted just fine...

What do I miss?

In your example, the line-edit does not literally accept the value 99.55656 . This can be confirmed by calling its hasAcceptableInput method, which returns False .

The validator is allowing the value to be entered, because doing so produces a valid Intermediate state. According to the docs , this can happen "if it is likely that a little more editing will make the input acceptable". So in the specific case of 99.55656 , deleting a 9 would produce a valid Acceptable state. This would seem to imply that "a little more editing" should be taken to mean adding or removing a single character (where the notation is StandardNotation ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM