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 and decimal place

QDoubleSpinBox and decimal place

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 3 Posters 1.9k Views 3 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have a QDoubleSpinBox on a form, the inputMethodHints is set to ImhFormattedNumbersOnly. In my class I have the keyPrevvEvent and I can see when the dot is pressed the event is received, however for some reason unknown to me, the control doesn't accept the dot, so if I type in 12.3 I only see 123.

    Why ?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #17

      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.

      Kind Regards,
      Sy

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

        Hi,

        What locale are you using ? Did you check if it does the same using , rather that . ?

        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
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          Just checked in the Qt Creator, locale: English, UnitedKingdom

          I'm using a smartCard reader ACR890, it is only has the . on the keypad.

          I just tried changing to UnitedStates, same problem.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi
            Just for fast test, i tried to change it here
            alt text
            and it gladly accepts the "." now. ( and rejects ",")

            I would check what keycode ACR890 sends for that key.

            1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              I've tried that, it doesn't fix it for me...the interesting thing is that the keyPressEvent does get the dot event when pressed and it shows a key value of 16777268, if I press any of the number keys, none of these are displayed in the keyPressEvent routine but they are excepted by the control.

              Kind Regards,
              Sy

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

                What keyboard are you using ?

                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
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by SPlatten
                  #7

                  Its the ACR890, a card reader:

                  https://www.acs.com.hk/en/products/372/acr890-all-in-one-mobile-smart-card-terminal/

                  I've tried several locale's now including UnitedKingdom, UnitedStates and HongKong, the problem exists with all of those.

                  Kind Regards,
                  Sy

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

                    Does it happen on the device itself or your getting inputs from the device to your computer ?

                    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
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by SPlatten
                      #9

                      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
                      

                      Kind Regards,
                      Sy

                      mrjjM 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        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
                        
                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @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) ?

                        1 Reply Last reply
                        0
                        • SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by
                          #11

                          Thats exactly what I'm saying.

                          Kind Regards,
                          Sy

                          mrjjM 1 Reply Last reply
                          0
                          • SPlattenS SPlatten

                            Thats exactly what I'm saying.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #12

                            @SPlatten
                            That almost seems like magic.
                            I wonder how keys come in then?
                            Its a completely plain QDoubleSpinBox, no overrides or event filters?

                            1 Reply Last reply
                            0
                            • SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on last edited by SPlatten
                              #13

                              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.

                              Kind Regards,
                              Sy

                              1 Reply Last reply
                              0
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #14

                                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?

                                1 Reply Last reply
                                0
                                • SPlattenS Offline
                                  SPlattenS Offline
                                  SPlatten
                                  wrote on last edited by
                                  #15

                                  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.

                                  Kind Regards,
                                  Sy

                                  1 Reply Last reply
                                  0
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #16

                                    ok. just checking
                                    so a normal QLineEdit will get the "." ?

                                    1 Reply Last reply
                                    0
                                    • SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by
                                      #17

                                      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.

                                      Kind Regards,
                                      Sy

                                      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