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 without annoying zeros after decimal point

QDoubleSpinBox without annoying zeros after decimal point

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.3k 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.
  • HarbH Offline
    HarbH Offline
    Harb
    wrote on last edited by
    #1

    Hey!
    I was wondering, if there is a simple way to make QDoubleSpibBox not to show all 10 zeros, If i set setDecimal(10)? I have spent several hours today, trying to figure out how to do that. My first idea was to add setCorrectDecimal(double d) slot, and connect it to valueChanged(double d) signal of QDoubleSpinBox. setCorrectDecimal set decimal on fly. It works! But the problem is that it work only when I use arrows to change value. If I try to change value by entering number from keybord, it doesn't work. I also have tried to override validate() method of QDoubleSpinBox in my own DoubleSpinBox class, but it doesn't work as I want.
    Any Ideas?

    kshegunovK 1 Reply Last reply
    0
    • J Offline
      J Offline
      Jan-Willem
      wrote on last edited by
      #2

      Perhaps by checking the value before it is shown, maybe in valueChanged?
      And then setting the decimal after checking which decimal != 0?

      Another place for something like this could be the paintEvent.

      1 Reply Last reply
      0
      • HarbH Harb

        Hey!
        I was wondering, if there is a simple way to make QDoubleSpibBox not to show all 10 zeros, If i set setDecimal(10)? I have spent several hours today, trying to figure out how to do that. My first idea was to add setCorrectDecimal(double d) slot, and connect it to valueChanged(double d) signal of QDoubleSpinBox. setCorrectDecimal set decimal on fly. It works! But the problem is that it work only when I use arrows to change value. If I try to change value by entering number from keybord, it doesn't work. I also have tried to override validate() method of QDoubleSpinBox in my own DoubleSpinBox class, but it doesn't work as I want.
        Any Ideas?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        QDoubleSpinBox::setDecimals isn't working?

        Read and abide by the Qt Code of Conduct

        HarbH 1 Reply Last reply
        0
        • kshegunovK kshegunov

          QDoubleSpinBox::setDecimals isn't working?

          HarbH Offline
          HarbH Offline
          Harb
          wrote on last edited by
          #4

          @kshegunov It work!
          But if the value of QDoubleSpinBox is 1 (double 1.0), after calling of setDecimals(10) you will see ten zeros after decimal point (1.0000000000), which looks extremely ugly. Especially when I want my QDoubleSpinBoxes accept values from 10e-15 to 10e15.

          kshegunovK 1 Reply Last reply
          0
          • HarbH Harb

            @kshegunov It work!
            But if the value of QDoubleSpinBox is 1 (double 1.0), after calling of setDecimals(10) you will see ten zeros after decimal point (1.0000000000), which looks extremely ugly. Especially when I want my QDoubleSpinBoxes accept values from 10e-15 to 10e15.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @Harb
            Why do you want the double spin box to accept such values?! What you're requesting is 30 orders of magnitude - roughly how the gold atom's nucleus' radius (about 7 fm) relates to the distance between Neptune and the Sun (about 4.5 billion kilometers) ... and then some more ...

            Read and abide by the Qt Code of Conduct

            HarbH 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @Harb
              Why do you want the double spin box to accept such values?! What you're requesting is 30 orders of magnitude - roughly how the gold atom's nucleus' radius (about 7 fm) relates to the distance between Neptune and the Sun (about 4.5 billion kilometers) ... and then some more ...

              HarbH Offline
              HarbH Offline
              Harb
              wrote on last edited by
              #6

              @kshegunov Hey! :)
              I know, if you are interested what i am doing, I will explain. Yes, maybe 10e15 is really too much. But still i need really wide span. I am doing software which reads different signals from files, plot them, manage and do basic analysis. So, it is some kind of oscilloscope, but it is more about visual representation and data managament, than analysis. So values of signals might be really different, it could be giga watts or it could be nano meters. So, after all, I think I really need this span. And this problem really is driving me crazy, right now I am sitting and reading Qt source code, to understand how does QDoubleSpinBox works internally.

              kshegunovK 1 Reply Last reply
              0
              • HarbH Harb

                @kshegunov Hey! :)
                I know, if you are interested what i am doing, I will explain. Yes, maybe 10e15 is really too much. But still i need really wide span. I am doing software which reads different signals from files, plot them, manage and do basic analysis. So, it is some kind of oscilloscope, but it is more about visual representation and data managament, than analysis. So values of signals might be really different, it could be giga watts or it could be nano meters. So, after all, I think I really need this span. And this problem really is driving me crazy, right now I am sitting and reading Qt source code, to understand how does QDoubleSpinBox works internally.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @Harb
                This just isn't practical. What would be the step for such a spin box?
                Just have a spinner that is between 999 and 0.001 and put a complementary dropdown with the measurement unit.

                Read and abide by the Qt Code of Conduct

                HarbH 1 Reply Last reply
                2
                • kshegunovK kshegunov

                  @Harb
                  This just isn't practical. What would be the step for such a spin box?
                  Just have a spinner that is between 999 and 0.001 and put a complementary dropdown with the measurement unit.

                  HarbH Offline
                  HarbH Offline
                  Harb
                  wrote on last edited by
                  #8

                  @kshegunov Well, I still think that it is practical. User shouldn't be imposed by such kind of restrictions. It always freak out anyone. In any case, thanks for your reply, course you gave me an idea to use just QLineText and QDoubleValidator instead of QDoubleSpinBox. Now it works perfectly, any double number can be entered from the keyboard. This is exectely what I wanted.

                  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