3

I want to make a QDoubleSpinBox that would format the value into currency so it would be readable by users.

Example.

enter image description here

So far I've accomplished these things:

  • set showGroupSeparator to true - but it will only work when focus is released.
  • used the valueChanged signal to update the group separators directly by calling ui->doubleSpinBox->setValue(amount);

    void DialogCashPayment::on_sbAmount_valueChanged(double arg1)
    {
        ui->sbAmount->setValue(arg1);
    }
    

The Problem is

The cursor position will not be in the correct position when the amount is > than 10k, sometimes the amount will completely disappear. in short its really buggy.

Is there any approach on this? Maybe I've overlooked something simple. Please raise a comment if something is not clear. Thanks!

m7913d
  • 10,244
  • 7
  • 28
  • 56
Binsoi
  • 383
  • 5
  • 13
  • You can try to change the cursor position manually to the desired position after you changed the value in your slot. – m7913d May 25 '17 at 10:19
  • Hi i also tried that in the docu but the closest i've got was the keyboardTracking but i could not find it. i was searching for something like setCursorPosition but found none. – Binsoi May 26 '17 at 01:44
  • You can get the line edit object with [`QDoubleSpinbox::lineEdit`](http://doc.qt.io/qt-5/qabstractspinbox.html#lineEdit). Then you can use [`QLineEdit::setCursorPosition`](http://doc.qt.io/qt-5/qlineedit.html#cursorPosition-prop). – thuga May 26 '17 at 06:59
  • Have you solved your problem? – m7913d May 30 '17 at 14:45

0 Answers0