Results 1 to 4 of 4

Thread: QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses

  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses

    Hello all,
    In my application, i have a spinBox whose minimum value is set to 10. Since I cannot display the same, I used specialValueText property to set it to ''--''.

    Now when the user clicks on the spinBox, cursor stays at the rightmost end, and the text ("--") will not clear off if 'backspace' or 'del' key is pressed.

    So, each and everytime, the user will have to select the text before he could enter/modify any value. Could anybody please tell how to resolve this issue? How to enable backspace/del keys? Otherwise, is there any way to set the text selected when the user clicks in the spinBox?

    Alternatively, Is there any way around to keep the spinBox blank so that when the user clicks (or the focus comes to the spinBox through pressing tab or setFocus(),) he/she is able to enter the values straightaway without going through the pain of selecting text?

    Thanks in advance
    Deepak

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

    Default Re: QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses

    You can call select the text if it is there and the widget gains focus. As for what is causing your problem, it is the validator that doesn't accept "-" as a valid value (which is a correct behaviour). The special value text is used not to enter the value manually but to use the increment/decrement keys to change values.

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses

    Thanks Wysota, I got the point.
    Now, my problem is how do we sense that the widget has gained focus?
    I searched QLineEdit documentation and couldnt find any signals which enabled us to sense that the user has 'clicked' in the LineEdit field.
    Also, after I set some input mask, say 000.000.000.000; for an IP field, when the user clicks anywhere in the field, the cursor stays there. I want to move it to the beginning. I found that QLineEdit::home() does the job, but again there should be some way out to find that lineedit has gained focus.

    any kind of help wil be highly appreciated.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses

    you can use QObject::installEventFilter for catching event from lineEdit. i.e. if you need to handle QFocusEvent you should do the following:
    Qt Code:
    1. SomeClass::SomeClass(QWidget *parent): QWidget(parent)
    2. {
    3. ....
    4. lineEdit->installEventFilter(this);
    5. ...
    6. }
    7.  
    8. bool SomeClass::eventFilter(QObject *o, QEvent *e)
    9. {
    10. if (o && (o == lineEdit) && (e->type() == QEvent::FocusIn)) {
    11. //do what you need
    12. }
    13. return QWiget::eventFIlter(o, e);
    14. }
    To copy to clipboard, switch view to plain text mode 

Tags for this Thread

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.