[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.
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?
Anyway I reproduce it! :)
The selection is done through:
And the solution is to call internally:
(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)
Pay attention that you regenerate/recompile too the .ui files which reference your double spinboxes.
>>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
- 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()
..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
- void form::dsbEditFinishedDeselect(QWidget *obj)
- #if DEBUG_SYNCH
- qDebug() << "*form::dsbEditFinishedDeselect " ;
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…