Spinboxes and Sliders

LukasT.dev@gmail.com lukast.dev at gmail.com
Sun Nov 15 17:05:55 CET 2009


Hello,

I'm trying to sliderify all my paintops and I come to this problem:
When I want to add QSlider to QDoubleSpinBox, there is no relevant signal/slot (no problem for qspinbox and qslider)

QSlider has valueChanged(int) and QDoubleSpinBox has valueChanged(double).
So I resolved it temporary like this:
I made kis_spray_shape_option Q_OBJECT and added slot void randomValueChanged(int value); 
There I count relative position of the slider and set appropriate value to the QDoubleSpinBox like this

void KisSprayShapeOption::randomValueChanged(int value)
{
    qreal relative = value / (qreal)m_options->randomSlider->maximum() ;
    m_options->randomWeightSPBox->setValue( relative * m_options->randomWeightSPBox->maximum() );
}

As you may notice, this solution is not very cool because I have to create slot per Slider/SPBox.
But on the other side, this solution gives better options like separete single step for Slider and SpinBox.
E.g. I set spinbox step to 0.5 so that you tweek the settings roughly and you can fine tune with slider or write exact value to spinbox.
From user perspective this solution works nicely but the code is not cool to maintain.

Another possibility is to use KDoubleNumInput which joins the QSlider and QSpinBox. But I have 
problems with it:

* when I enable the optional slider in designer , the slider is not visible. Mek looked at it and found but that layout() is not called or something.
* I want to layout like this [1] and not like this [2], because [2] is much less usable because I want to fine tune - I need more place for slider. 

I tested grid layout and vertical layout in Qt Designer. Both results are wrong like in [2].

[1] http://lukast.mediablog.sk/tmp-i/uglycode-good-layout.jpg
[2] http://lukast.mediablog.sk/tmp-i/knum-bad-layout.jpg

* I did not notice if I can have separate step for slider and separate step for SpinBox in KDoubleNumInput but probably not
* I'm trying to avoid to write custom widgets code and use UI files as much as possible

What would you advice me?
Which solution you consider the best and why?

1. Patch all paintops in current way like I described
- ugly code 
+ nicely working solution ( separate steps for slider/spinbox)

2. Use KDoubleNumInput 
- ugly layout, not very usable till somebody hint how can I layout the way I want
- no separate steps
- buggy in Designer

3. Write custom KisDoubleSlider for paintops with signal valueChanged(double)
- I don't know

Lukas


More information about the kimageshop mailing list