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. [SOLVED] QDoubleSpinBox - hidding decimal when the number is Integer?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QDoubleSpinBox - hidding decimal when the number is Integer?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    I have this QDoubleSpinBox: "https://www.dropbox.com/s/l8xm7h0fb5b8rr9/SpinBoxQDouble.png?dl=0":https://www.dropbox.com/s/l8xm7h0fb5b8rr9/SpinBoxQDouble.png?dl=0

    When I want to edit the QDoubleSpinBox, I set the value inside and would like to hide the decimal if the number is Integer*
    *(number - ((int)number) = 0.0)

    I tried subclassing QDoubleSpinBox and re-implement textFromValue and creating the QString there without the decimal, but the function never seem to be called? (still show the decimals)

    Is there an easier way that i'm missing?

    Thanks!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    1
    • B Offline
      B Offline
      Binary91
      wrote on last edited by
      #2

      Do you have some code?
      How do you "hide" the decimals?
      Try catching the signal valueChanged(), check whether it is an integer or not and then use setDecimals(0)...

      [EDIT]
      Problem is, that neighter valueChanged(double) nor valueChanged(const QString &) fire when comma is pressed, so maybe you should catch the keyPressEvent and check spinbox text via text().count(",") --> if greater then zero, set decimals to two, otherwise to zero... maybe that works for you...

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Can you show your implementation ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          Hey guys thanks for the reply,
          Finally I went back to using a standard QDoubleSpinBox for now. The reason to hide the decimals is purely aesthetic so it can wait..

          The code was something like :

          @QString myDoubleSpinBox::textFromValue ( double value ) {

          if(value - ((int)value) != 0)
          return QString::number(value, 'f', 2);
          else
          return QString::number((int)value));
          }@

          And the decimals in the QDoubleSpinBox use "dot" (.) not commas here it seems, maybe it use the locale


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Indeed comma vs point comes from the locale

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maximus
              wrote on last edited by
              #6

              One thing to consider would be to have an option on the QDoubleSpinBox (decimal hidden) so that if the user type "45" it doesn't change to "45.00" once finish editing, let the SpinBox accept double but only show the decimals if the decimal symbol have been pressed (, or . depending on the locale).

              Have a great day!


              Free Indoor Cycling Software - https://maximumtrainer.com

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You can try making a feature request (or see if such one was already made)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #8

                  Alright will check to do that.

                  I have checked on : https://qt-project.org/search/tag/feature~request
                  but not sure how the feature request works, can't seem to find where to create a new request.
                  Sorry for my noobiness ;)


                  Free Indoor Cycling Software - https://maximumtrainer.com

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    The "bug report system":http://bugreports.qt-project.org is the right place. Just select the feature request option rather than bug. But first, take the time to check whether there was already something about it

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

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