Solved QDoubleSpinBox and decimal place
-
Does it happen on the device itself or your getting inputs from the device to your computer ?
-
Sorry, I don't really understand what you are asking, I'm using Qt Creator to deploy the application to the target, I'm using the device directly when I push the following:
1 2 . 3
On the display I see only:
123
If I monitor in Qt Creator with a breakpoint in keyPressEvent, only pressing:
.
Results in a call to the routine, pressing any of the numbers does not. The routine receives and event with the key returned as:
16777268
-
@SPlatten
Hi
ok so it is on the device.
But are you saying when you type 12.3, in keyhandler the dot is seen but never 1,2,3
but still they show up in the widget? (but not . even it was seen) ? -
Thats exactly what I'm saying.
-
@SPlatten
That almost seems like magic.
I wonder how keys come in then?
Its a completely plain QDoubleSpinBox, no overrides or event filters? -
No, nothing I just dropped it in from the palette on the left, changed the geometry and font size and that is all.
Looking at the object in Qt Creator, to be precise, this is what I've changed:
geometry [(10,40), 221 x 51] font A [Ubuntu, 24] alignment AlignHCenter, AlignVCenter maximum 99999999.990000 singleStep 0.010000
In the class prototype:
void keyPressEvent(QKeyEvent* pEvent); private slots: void on_spbxAmount_valueChanged(const QString& strText);
The implementation for the above:
void clsSaleForm::keyPressEvent(QKeyEvent* pEvent) { int intKey = pEvent->key(); qDebug() << intKey; } void clsSaleForm::on_spbxAmount_valueChanged(const QString& strText) { bool blnNothing = (strText.isEmpty() || strText.toDouble() == 0); ui->pbtnNext->setEnabled(!blnNothing); }
I just tried to replicate this behaviour on my iMAC, created with the same settings and it worked perfectly, so it must be an issue with the version of Qt on the Ubuntu build.
On my iMAC I'm using:
Qt Creator 4.9.1 Based on Qt 5.12.3 (Clang 10.0 (Apple), 64 bit) Built on May 26 2019 21:14:16 From revision 168e91b618
And on the laptop running Ubuntu 14.04:
Qt Creator 3.0.1 Based on Qt 5.2.1 (GCC 4.8.2, 32 bit) Built on Apr 9 2014 at 09:14:10
Sadly I cannot upgrade the Ubuntu Qt as the SDK I'm using is part of the ACR SDK and there doesn't appear to be an update.
-
Hi
Ah, you overrode forms keypress, not the QDoubleSpinBox's.
thats why you saw . and not 1,2,3.Are you 100% sure you set locale on the QDoubleSpinBox since its
not shown in modifications? -
Yes, 100% and I've been back to check it several times. I am currently implementing a solution not using the QDoubleSpinBox but just a regular QLineEdit with regular expression.
-
ok. just checking
so a normal QLineEdit will get the "." ? -
Yes, the regular expression will restrict what it can and cannot accept and the keyPressEvent handler will receive the dot and insert it into the line edit control.