[sorta Solved] QDoubleSpinBox..How to clear selected/highlighted text?
When I click the arrow buttons of a QDoubleSpinBox the text is highlighted (selected?) at the click. This is probably normal, but the highlighting makes it harder to read the numbers in the attached QLineEdit
I have tried just about everything to get rid of the highlighting.
clearFocus()
change focus to another widget
access the pointer to the QLineEdit (QLineEdit * QAbstractSpinBox::lineEdit () const ) and then deselect()
clear() and then setValue()
tried setting all the different focusPolicy possibilites
tried changing the stylesheet highlight text color to not the blue highlight color
Is there something I’m missing?
4 replies
Anyway I reproduce it! :)
The selection is done through:
- myDoubleSpinBox->lineEdit()->selectAll();
And the solution is to call internally:
- this->lineEdit()->deselect();
(like you suggest)
Now the problem is ‘when’ you do this! If you do it in the slot which gets the values it’s too early, the selectAll() is done AFTER the signal valueChanged()!
If ‘only’ the steps ± are the problem, inherits the QDoubleSpinBox and redefine the stepBy() function like this:
- void MyDoubleSpinBox::stepBy(int steps)
- {
- lineEdit()->deselect();
- }
Pay attention that you regenerate/recompile too the .ui files which reference your double spinboxes.
Thanks…
>>Could give (you) the parameters of your QDoubleSpinBox ?
They’re all the standard settings as the QDoubleSpinBox is dropped on a form using Qt Creator. The ui-> convention used below is the Creator generated code in the .h file
- private:
- Ui::form *ui;
>>Now the problem is ‘when’ you do this! If you do it in the slot which gets the values it’s too early
Doh! That’s when I was trying everything…in the valueChanged slot…
- void form::on_dsb_valueChanged(double val)
I tried moving the deselect() call to the editingFinished slot for the dsb…
- void form::on_dsb_editingFinished()
- {
- ui->dsb->lineEdit()->deselect();
- }
..but get the error..
/Library/Frameworks/QtGui.framework/Headers/qabstractspinbox.h:157: error: ‘QLineEdit* QAbstractSpinBox::lineEdit() const’ is protected within this context
I also tried mapping the editingFinished signal to a generic slot and casting the widget pointer to a dsb…same error as above..protected
- {
- #if DEBUG_SYNCH
- qDebug() << "*form::dsbEditFinishedDeselect " ;
- #endif
- dsb->lineEdit()->deselect();
- }
Not sure that it matters, but this is on a Mac..haven’t tried it on my Win7 dev box, yet.
Cheesy, but this works…
- {
- #if DEBUG_SYNCH
- qDebug() << "*form::dsbEditFinishedDeselect " ;
- #endif
- QString nohighlights = "color: black; background: white; selection-color: black; selection-background-color: white;"
- dsb->setStyleSheet( nohighlights );
- }
You must log in to post a reply. Not a member yet? Register here!
