PDA

View Full Version : how to change the spinbox background color when user edit



wagmare
14th February 2014, 12:03
hi friends,
I just want to know how i can change the background color of a qspinbox when the user click on the spinbox to edit it and once user completes editing i have to revert back to old background state.

proper way is to use signals of valueChange and editFinished or touse stylesheet ..?
im n0t able to find any stylesheet for edit in qspinbox

please help me .

anda_skoa
14th February 2014, 14:08
proper way is to use signals of valueChange and editFinished or touse stylesheet ..?

This is not an "or" question.

You need two things:
1) a way to detect user editing and finish editing, most likely through signals
2) a way to modify the widget's appearance when necessary. That can be done through a style sheet or by manipulating the widget's palette.



im n0t able to find any stylesheet for edit in qspinbox

All widgets can have a stylesheet applied, so that property is documented in QWidget

Cheers,
_

atenakid
20th February 2014, 05:36
This is not an "or" question.

You need two things:
1) a way to detect user editing and finish editing, most likely through signals
2) a way to modify the widget's appearance when necessary. That can be done through a style sheet or by manipulating the widget's palette.


All widgets can have a stylesheet applied, so that property is documented in QWidget

Cheers,
_

Hi, i got the same problem. My dialog contains several QspinBox, and it does not highlight which one has been changed like in QComboBox.
One solution would be using signal and slot like


connect(qspinBox, SINGAL(currentIndexChanged(int)), this, SLOT( changeQspinBackground());

Then, Do i have to implement changeQSpinBackground for every Qspinbox?
However, I use many QSpinbox, how can I do this in more effective way?

Thanks you,

anda_skoa
20th February 2014, 10:05
You can get the sender of a signal using QObject::sender()



void SomeClass::someSlot()
{
QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender());
if (!spinBox)
return;

// do something with spinBox
}


Alternatively use a QSignalMapper

Cheers,
_