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. QSpinbox editingFInished signal on up/down arrow press

QSpinbox editingFInished signal on up/down arrow press

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    sayan275
    wrote on 6 Feb 2020, 05:02 last edited by sayan275 2 Jun 2020, 05:03
    #1

    I went through a lot of posts regarding QSpinBox signals editingFinished and valueChanged, but not able solve my problem, ie,

    1. I want editingFinished signal to be emitted, when user enters any value and presses "Enter".[DONE]
    2. The user can change value with the up/down arrows either by keyPress or mousePress. This can be done by valueChange signal, but not editingFinished

    So to achieve both, I'm facing problem, Suppose I want to enter 10000, so valueChanged is emitted with 1, 10, 100, 1000, 10000 Which I don't want, rather it should emit when user pressed enter after entering 10000. So this is done by avoiding valueChanged and connecting to &QAbstractSpinbox::editingFinished.

    connect(ui->spinBox, &QSpinBox::editingFinished,
            this, [&]()
    {
        ui->label->setText(QString::number(ui->spinBox->value()));
    });
    

    But I want the up/down arrows to work also. so for this again valueChanged is required.

    Is there any means to achieve it directly, rather than adding my own spinbox class and overriding the events for up/down arrow click/press.

    Any suggestion is appreciated.

    P J 2 Replies Last reply 6 Feb 2020, 05:25
    0
    • S sayan275
      6 Feb 2020, 05:54

      @jsulm
      Case 1: If user presses arrow keys...the value would change...no enter required to be pressed
      Case 2: if user enters some value in the spinbox, it shouldn't emit valueChanged, unless enter is pressed.
      Because, what happens is, If user wants to enter 10000, so 5 times valueChanged will emit, with 1, 10, 100, 1000, 10000.
      But it should be only once when user hits enter after entering 10000. This is done by editingFinished and not handling valueChanged. But then the value can't be changed from arrow keys, as valueChanged is not connected.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 6 Feb 2020, 05:58 last edited by
      #8

      @sayan275 I think this is exactly what you need: https://doc.qt.io/qt-5/qabstractspinbox.html#keyboardTracking-prop

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 6 Feb 2020, 06:44
      2
      • S sayan275
        6 Feb 2020, 05:02

        I went through a lot of posts regarding QSpinBox signals editingFinished and valueChanged, but not able solve my problem, ie,

        1. I want editingFinished signal to be emitted, when user enters any value and presses "Enter".[DONE]
        2. The user can change value with the up/down arrows either by keyPress or mousePress. This can be done by valueChange signal, but not editingFinished

        So to achieve both, I'm facing problem, Suppose I want to enter 10000, so valueChanged is emitted with 1, 10, 100, 1000, 10000 Which I don't want, rather it should emit when user pressed enter after entering 10000. So this is done by avoiding valueChanged and connecting to &QAbstractSpinbox::editingFinished.

        connect(ui->spinBox, &QSpinBox::editingFinished,
                this, [&]()
        {
            ui->label->setText(QString::number(ui->spinBox->value()));
        });
        

        But I want the up/down arrows to work also. so for this again valueChanged is required.

        Is there any means to achieve it directly, rather than adding my own spinbox class and overriding the events for up/down arrow click/press.

        Any suggestion is appreciated.

        P Offline
        P Offline
        Pradeep P N
        wrote on 6 Feb 2020, 05:25 last edited by
        #2

        Hi @sayan275

        AFAIK, by default the present QSpinBox wont support your requirement.
        I would prefer you to customize your own SpinBox so handling of the signals is in your control.

        All the best.

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        S 1 Reply Last reply 6 Feb 2020, 05:42
        0
        • S sayan275
          6 Feb 2020, 05:02

          I went through a lot of posts regarding QSpinBox signals editingFinished and valueChanged, but not able solve my problem, ie,

          1. I want editingFinished signal to be emitted, when user enters any value and presses "Enter".[DONE]
          2. The user can change value with the up/down arrows either by keyPress or mousePress. This can be done by valueChange signal, but not editingFinished

          So to achieve both, I'm facing problem, Suppose I want to enter 10000, so valueChanged is emitted with 1, 10, 100, 1000, 10000 Which I don't want, rather it should emit when user pressed enter after entering 10000. So this is done by avoiding valueChanged and connecting to &QAbstractSpinbox::editingFinished.

          connect(ui->spinBox, &QSpinBox::editingFinished,
                  this, [&]()
          {
              ui->label->setText(QString::number(ui->spinBox->value()));
          });
          

          But I want the up/down arrows to work also. so for this again valueChanged is required.

          Is there any means to achieve it directly, rather than adding my own spinbox class and overriding the events for up/down arrow click/press.

          Any suggestion is appreciated.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 6 Feb 2020, 05:29 last edited by
          #3

          @sayan275 said in QSpinbox editingFInished signal on up/down arrow press:

          rather it should emit when user pressed enter

          So, do you expect your users to use up/down and submit the result with enter? This would be unusual and counter-intuitive.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sayan275
            wrote on 6 Feb 2020, 05:41 last edited by
            #4

            no actually.
            There are 2 usecases;

            1. User can enter value and press enter
            2. User can change value by the arrow keys with mouse and keypress
            J 1 Reply Last reply 6 Feb 2020, 05:47
            0
            • P Pradeep P N
              6 Feb 2020, 05:25

              Hi @sayan275

              AFAIK, by default the present QSpinBox wont support your requirement.
              I would prefer you to customize your own SpinBox so handling of the signals is in your control.

              All the best.

              S Offline
              S Offline
              sayan275
              wrote on 6 Feb 2020, 05:42 last edited by
              #5

              @Pradeep-P-N
              Thanks
              I kept that as the last option.

              1 Reply Last reply
              0
              • S sayan275
                6 Feb 2020, 05:41

                no actually.
                There are 2 usecases;

                1. User can enter value and press enter
                2. User can change value by the arrow keys with mouse and keypress
                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 6 Feb 2020, 05:47 last edited by
                #6

                @sayan275 OK, I think I understand now what you want to achieve. But what would happen if user would use up/down keys without pressing enter when finished? User would expect that the current value will take effect but it will not (as he/she did not press enter). You would need to make it clear for the user that the value needs to be submitted using enter key.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply 6 Feb 2020, 05:54
                0
                • J jsulm
                  6 Feb 2020, 05:47

                  @sayan275 OK, I think I understand now what you want to achieve. But what would happen if user would use up/down keys without pressing enter when finished? User would expect that the current value will take effect but it will not (as he/she did not press enter). You would need to make it clear for the user that the value needs to be submitted using enter key.

                  S Offline
                  S Offline
                  sayan275
                  wrote on 6 Feb 2020, 05:54 last edited by
                  #7

                  @jsulm
                  Case 1: If user presses arrow keys...the value would change...no enter required to be pressed
                  Case 2: if user enters some value in the spinbox, it shouldn't emit valueChanged, unless enter is pressed.
                  Because, what happens is, If user wants to enter 10000, so 5 times valueChanged will emit, with 1, 10, 100, 1000, 10000.
                  But it should be only once when user hits enter after entering 10000. This is done by editingFinished and not handling valueChanged. But then the value can't be changed from arrow keys, as valueChanged is not connected.

                  J 1 Reply Last reply 6 Feb 2020, 05:58
                  0
                  • S sayan275
                    6 Feb 2020, 05:54

                    @jsulm
                    Case 1: If user presses arrow keys...the value would change...no enter required to be pressed
                    Case 2: if user enters some value in the spinbox, it shouldn't emit valueChanged, unless enter is pressed.
                    Because, what happens is, If user wants to enter 10000, so 5 times valueChanged will emit, with 1, 10, 100, 1000, 10000.
                    But it should be only once when user hits enter after entering 10000. This is done by editingFinished and not handling valueChanged. But then the value can't be changed from arrow keys, as valueChanged is not connected.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 6 Feb 2020, 05:58 last edited by
                    #8

                    @sayan275 I think this is exactly what you need: https://doc.qt.io/qt-5/qabstractspinbox.html#keyboardTracking-prop

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    S 1 Reply Last reply 6 Feb 2020, 06:44
                    2
                    • J jsulm
                      6 Feb 2020, 05:58

                      @sayan275 I think this is exactly what you need: https://doc.qt.io/qt-5/qabstractspinbox.html#keyboardTracking-prop

                      S Offline
                      S Offline
                      sayan275
                      wrote on 6 Feb 2020, 06:44 last edited by
                      #9

                      @jsulm Yes...it's perfect..Thanks

                      1 Reply Last reply
                      0

                      5/9

                      6 Feb 2020, 05:42

                      • Login

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