PDA

View Full Version : SpinBox like a slider



Alundra
29th October 2013, 14:26
Hi all,
QDoubleSpinBox is nice but contains some feature who is bad for a soft.
The idea is to have a QDoubleSpinBox who wors like a slider so it's like a button who show the value but when stay clicked on it it becomes a slider and if you double click on it, it become a text-edit to change the value by hand.And that should allow to use the dot as separator too : "3,14"->"3.14".
This is the idea but I don't know how to achieve that correctly because it's not really a push button, it's not really a QTextEdit and it's not really a slider...
Thanks for the help

anda_skoa
30th October 2013, 10:14
One thing you could try:

Create a widget that either subclasses QStackedWidget or contains one.
Put a slider and a QLineEdit into the stacked widget.

Implement mouseDoubleClicked() so that it switches from the slider to the line edit.
When the input of the line edit is finished, switch back

Cheers,
_

Alundra
30th October 2013, 13:44
I didn't knew QStackedWidget, I tried and the switch works nicely but one problem remains who is the slider who needs to be like a button, so the slider must works on all the surface of the widget and not just the bar of the slider like the basic slider widget does.
The goal is to have a widget of this style : http://uppix.com/f-spinbox_slider5271107600146aae.png.
The stylesheet is the best way to achieve that or a better solution exist ?
Thanks for the help

anda_skoa
30th October 2013, 18:10
I am afraid I don't understand either the problem, nor how the linked image has anything to do with a slider.

Cheers,
_

Alundra
30th October 2013, 23:19
It's fast but you can see here :
http://www.youtube.com/watch?v=PjSFbPv3SLc
at 2min01s

anda_skoa
31st October 2013, 08:45
In this case it is probably easier to implement your own widget.

Maybe starting with a QDoubleSpin box as a base class, set it to read-ony at the beginning, switching to read/write when double clicked.
Normal mouse handling for the "slider" effect.

Cheers,
_

Alundra
31st October 2013, 14:03
Ok, thanks for the tip, but one problem remains, when you edit the value you can write "10.0001" but that will be truncated because of decimals allowed.
Is it possible to counter that, to set the number of decimals based on the value ?
Is the virtual valueFromText function the best to have that correctly ?
Thanks for the help

anda_skoa
1st November 2013, 11:53
valueFromText sounds like a good choice.

Cheers,
_

Alundra
1st November 2013, 18:10
The real problem now is how to allow the lineEdit() of QDoubleSpinBox to write infinite decimals before the trick of setDecimals.
I tried some method but no one worked, sounds like not so easy that sounds.

anda_skoa
1st November 2013, 19:31
The line edit is probably using a QDoubleValidator as its validator(), you might need a different one.

Cheers,
_

Alundra
3rd November 2013, 01:34
I use this one :

const QString DecimalPointString = ( LocalDecimalPoint != "." ) ? LocalDecimalPoint : "";
lineEdit()->setValidator( new QRegExpValidator( QRegExp( "-?[0-9]*[." + DecimalPointString + "]?[0-9]{,2}" ), this ) );
He works good to have only number, - and . but it doesn't remove the block of decimals.

Alundra
8th November 2013, 04:17
Using :

lineEdit()->setValidator( new QRegExpValidator( QRegExp( "-?[0-9]*[." + DecimalPointString + "]?[0-9]{,}" ), this ) );
That works to not have limit on decimals when write on the LineEdit but I have a last prob.

// Set default decimals.
setDecimals( 15 );

// Set default min/max.
setMinimum( -DBL_MAX );
setMaximum( +DBL_MAX );
This code make the lineEdit really big on the width.I can't have it little.
Maybe a fix exist ?
Thanks for the help