Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDoubleSpinBox : Setting thousand separator while user is typing cursor position bug
Forum Updated to NodeBB v4.3 + New Features

QDoubleSpinBox : Setting thousand separator while user is typing cursor position bug

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    binsoii
    wrote on last edited by
    #1

    Hi!

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

    So far i've accomplished these things:

    • set showGroupSeparator to true - but i will only work when focus is released.
    • used the valueChange to update the amount by ui->doubleSpinBox->setValue(amount);

    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? Thanks!

    VRoninV 1 Reply Last reply
    0
    • B binsoii

      Hi!

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

      So far i've accomplished these things:

      • set showGroupSeparator to true - but i will only work when focus is released.
      • used the valueChange to update the amount by ui->doubleSpinBox->setValue(amount);

      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? Thanks!

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @binsoii said in QDoubleSpinBox : Setting thousand separator while user is typing cursor position bug:

      in short its really buggy.

      Well... what you describe above is the exact same behaviour you obtain in MS Office so we might as well argue this behaves as intended and there are no bugs.

      You might probably be better off building your own custom widget with QLineEdit+QValidator+2*QPushButton

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 1 Reply Last reply
      2
      • VRoninV VRonin

        @binsoii said in QDoubleSpinBox : Setting thousand separator while user is typing cursor position bug:

        in short its really buggy.

        Well... what you describe above is the exact same behaviour you obtain in MS Office so we might as well argue this behaves as intended and there are no bugs.

        You might probably be better off building your own custom widget with QLineEdit+QValidator+2*QPushButton

        B Offline
        B Offline
        binsoii
        wrote on last edited by
        #3

        @VRonin Thanks! gosh building my own custom widget is quite overwhelming. can you give some pointers or tips about this? :)

        VRoninV 1 Reply Last reply
        0
        • B binsoii

          @VRonin Thanks! gosh building my own custom widget is quite overwhelming. can you give some pointers or tips about this? :)

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          @binsoii said in QDoubleSpinBox : Setting thousand separator while user is typing cursor position bug:

          gosh building my own custom widget is quite overwhelming

          The below is just a starting point

          #include <QWidget>
          #include <QLineEdit>
          #include <QPushButton>
          #include <QDoubleValidator>
          #include <QGridLayout>
          class TestUser : public QWidget
          {
              Q_OBJECT
              Q_DISABLE_COPY(TestUser)
          public:
              explicit TestUser(QWidget *parent = Q_NULLPTR)
                  :QWidget(parent)
                  , m_step(1.0)
              {
                  m_editor=new QLineEdit(this);
                  m_editor->setValidator(new QDoubleValidator(this));
                  m_editor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
                  m_increaseButton=new QPushButton(QStringLiteral("\u23F6"),this);
                  m_decreaseButton=new QPushButton(QStringLiteral("\u23F7"),this);
                  connect(m_increaseButton,&QPushButton::clicked,this,[this](){m_editor->setText(m_editor->locale().toString(m_editor->locale().toDouble(m_editor->text())+m_step));});
                  connect(m_decreaseButton,&QPushButton::clicked,this,[this](){m_editor->setText(m_editor->locale().toString(m_editor->locale().toDouble(m_editor->text())-m_step));});
                  connect(m_editor,&QLineEdit::textChanged,this,[this](){Q_EMIT valueChanged(m_editor->locale().toDouble(m_editor->text()));});
                  QGridLayout* mainLay=new QGridLayout(this);
                  mainLay->setSpacing(0);
                  mainLay->addWidget(m_editor,0,0,2,1);
                  mainLay->addWidget(m_increaseButton,0,1);
                  mainLay->addWidget(m_decreaseButton,1,1);
              }
              double step() const {return m_step;}
              void setStep(double step){if(m_step!=step){m_step=step; Q_EMIT stepChanged(m_step);}}
              Q_SIGNAL void stepChanged(double);
              Q_SIGNAL void valueChanged(double);
          private:
              QLineEdit* m_editor;
              QPushButton* m_increaseButton;
              QPushButton* m_decreaseButton;
              double m_step;
          };
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved