Results 1 to 8 of 8

Thread: SpinBox: received value depends on "up-down arrows", pressing enter or digit by hand

  1. #1
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default SpinBox: received value depends on "up-down arrows", pressing enter or digit by hand

    Hi,
    I am a complete newbie as regards Qt and I have just started programming with it.
    My problem regards SpinBox.

    I need to distinguish if the value received from SpinBox depends on:
    1. changing value using up down arrows
    2. pressing enter
    3. editing by hand the value (one digit at a time)

    I have found that I can distinguish if the value is enter implementing _editingFinished() function as follows.
    I wonder if there is something similar to the hasFocus property for understanding when the changed values depends on clicking up down arrows.


    Qt Code:
    1. void MainWindow::on_doubleSpinBox_editingFinished()
    2. {
    3. if (ui->doubleSpinBox->hasFocus()) // Enter
    4. {
    5. qDebug() << "Enter pressed";
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    I have found that I can distinguish if the value is enter implementing
    the value from a spinbox is never 'enter'.

    have you read these?
    qspinbox
    qabstractspinbox
    they don't don't have the signals you're after (for a pretty good reason)
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    Quote Originally Posted by chobin View Post
    I need to distinguish if the value received from SpinBox depends on:
    1. changing value using up down arrows
    2. pressing enter
    3. editing by hand the value (one digit at a time)
    Why do you care how the value was entered? Seems an unusual thing, especially since item 2 does not change or set a value.

  4. #4
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    The project I am working on consists in a gui which sends data to a DSP.
    At the changing of the spinBox value, a register in the DSP is updated.

    When the up-down arrows of the SpinBox is used, the register is updated in the DSP, and this is ok.

    When the SpinBox valued is changed by hand, at every digit modified, the value is updaetd in the DSP.
    For example if the default value is 50.00 and I want to send the value 12.34, in the current state, I will send to the DSP uncomplete values (for example 10.00 -> 12.00 -> 12.30) before sending the value 12.34.

    In order to avoid this I thought to discriminate if the value changed depends on:
    1. by hand editing
    2. up-down arrow clicking

    If the the value has been edited by hand I need to catch the enter key (ignoring the digit modified by hand before the enter) and then to send the value to the DSP;
    if the the value depends on up-down arrows clicking the value can be immediately send to the DSP.

    Every suggestion is more than welcom!

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    The simplest solution is to add an 'apply' button. Then the user has control over when the DSP is updated.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    Hi Amleto,

    Thanks for your help!
    As apply button do you mean to use a QLineEdit + a QPushButton?
    Before deciding to modify the components of the GUI (actually I guess that the GUI users would not approve a similar change), I would prefer to evaluate some other solutions (if exist), even if more complicated.

  7. #7
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    No need to remove your spinbox. Spinbox + apply button.

    If not acceptable, then you need to subclass QSPinBox or even QAbstractSpinBox
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SpinBox: received value depends on "up-down arrows", pressing enter or digit by h

    An alternative would be to use a timer that would apply the current value if it hasn't been changed for a while (e.g. 1 second). Such delay is acceptable and should allow the user to enter the value he really wants without passing intermediate values.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 20th July 2011, 11:37
  2. Replies: 5
    Last Post: 17th June 2011, 09:43
  3. The "Signal received" death popup
    By CrazyDave in forum Newbie
    Replies: 1
    Last Post: 2nd October 2010, 00:12
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.