Reversing the arrows in a QSpinBox
How can I "flip" the arrows in a QSpinBox so that when you push down, the number increases and when you push up, the number decreases?
I want to use the spinbox to set depth-value so my users found it more intuitive that down would be an increase of depth.
I have subclassed the QSpinBox (actually a QDoubleSpinBox) and overridden the wheelEvent so that one is taken care of.
I could look for mousepress and see if the mouse is inside the up or down arrow, maybe, but when the value is 0 (minValue), the down-arrow is gray, so just overriding the values here would not be any good. I want the up-arrow to be gray when value is at minValue.
I've tried googling for this and the closest I've come is to completely redefine the QStyle painting routine. I found this also in "C++ GUI programming with Qt 4". This seemed overly complex and I don't want to redefine the style if this means that I would set the spinBox style to something that may be unlike the native look in different OS'es.
Is there any painting routine I could relatively easily override where I just reposition the arrows? Or any other place I should look?
Re: Reversing the arrows in a QSpinBox
Reimplement QAbstractSpinBox::stepBy() :
Code:
void MySpinbox::stepBy(int step) {
}
Re: Reversing the arrows in a QSpinBox
Thanks, but it did not work for the extreme values. When the value is 0.0, the step-function is prevented. I will look more into this. Also the problem with the gray arrow was still there
Re: Reversing the arrows in a QSpinBox
Let's try something else then. Reimplement valueFromText and textFromValue to work on negative numbers and set your maximum as 0 and your minimum as -something. Then other things should work properly.
Code:
double MySpinbox
::valueFromText(const QString &text
) const { return -QDoubleSpinBox::valueFromText(text
);
}
Re: Reversing the arrows in a QSpinBox
This seems to fix it for the textFromValue-part, but it looks like the validator prevents the input of positive numbers when I have a range of [-45.0, 0.0]
I will look into that. I'm much closer to this working now than a few hours ago. Thanks!
Re: Reversing the arrows in a QSpinBox
You can reimplement validate() for that.
Re: Reversing the arrows in a QSpinBox
I also subclassed QDoubleSpinBox to override the scrolling function.