PDA

View Full Version : QSpinBox - specialValueText problem - wont accept 'backspace' or 'del' keypresses



deepakn
21st August 2008, 10:30
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

wysota
21st August 2008, 11:29
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.

deepakn
22nd August 2008, 07:04
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.

spirit
22nd August 2008, 07:46
you can use QObject::installEventFilter for catching event from lineEdit. i.e. if you need to handle QFocusEvent you should do the following:


SomeClass::SomeClass(QWidget *parent): QWidget(parent)
{
....
lineEdit->installEventFilter(this);
...
}

bool SomeClass::eventFilter(QObject *o, QEvent *e)
{
if (o && (o == lineEdit) && (e->type() == QEvent::FocusIn)) {
//do what you need
}
return QWiget::eventFIlter(o, e);
}