Conversation
from PyQt6 import QtCore
print('Qt Version', QtCore.QT_VERSION_STR)
loc_def = QtCore.QLocale('en')
loc_eur = QtCore.QLocale('de')
numbers = [123.456789, 123456.789, 123456789.]
for number in numbers:
s1 = loc_def.toString(number, 'g')
s2 = loc_eur.toString(number, 'g')
print(f'{s1} {s2}')Qt6 versions up to 6.8.x seem to have a bug in capitalizing the exponent character even though 'g' (and not 'G') was specified. Another issue exposed here is that there's also the https://doc.qt.io/qt-6/qlocale.html#groupSeparator that is locale dependent. |
|
Relevant points:
The fix is also backported to 6.8 and 6.5, but that won't be in the pypi wheels. |
|
@pijyoi , that's some thorough investigation for the CI-failure! I've updated the tests to expect failure for old versions of Qt. Regarding group separator, I did consider it. But it's not supported in the standard Qt DoubleSpinBox, it wasn't implemented in the previous version of this SpinBox, and I felt it would be too complex to implement for a niche feature of a niche GUI-component. |
tests/widgets/test_spinbox.py
Outdated
| (0, '0 mV', dict(suffix='V', dec=True, siPrefix=True, minStep=15e-3)), | ||
| ]) | ||
| def test_SpinBox_formatting(value, expected_text, opts): | ||
| if 'e' in expected_text and compare_semantic_versions(pg.Qt.QtVersion, '6.9.0') < 0: |
There was a problem hiding this comment.
The capitalized-'E' bug is not present in Qt5.
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore
def display():
print(spinbox.value())
pg.mkQApp()
spinbox = pg.SpinBox(value=123456.789, step=1)
spinbox.setLocale(QtCore.QLocale('en'))
spinbox.sigValueChanged.connect(display)
spinbox.setMinimumHeight(40)
spinbox.show()
pg.exec()On startup, the string "123,456" is displayed. (group separator has been added by Qt) So this means that the user, when entering numbers manually, must remove any group separators from the existing displayed string value. |
|
Fixed the group separator issue by removing group separators from the number string produced by QLocale.toString() (the python float formatter didn't add these, so this was a new issue). FAILED pyqtgraph/examples/test_examples.py::testExamples[ MouseSelection.py - PySide2 ] - Failed: Traceback (most recent call last): Failed MouseSelection Example Test Located in MouseSelection.py |
|
And now I screwed the whole PR up because I tried to merge this branch on my fork onto another branch on my fork, and there were conflicts. |
733099c to
e7b542b
Compare
Spinboxes in Qt are locale-aware, in the sense that they use a period or a comma as a decimal separator depending on locale. This pull request fixes pyqtgraph's Si-scaling spinbox so it acts the same way.