Create a video player slider seeker with QSlider
-
I'm using a library to create a video player with Qt and this library returns for me the video current position as float and also as a percentage, for example, this video has the length of
5568
and the event/signalpositionChanged
returns me this:0.00329063
0.0478329
0.0957256
0.14266
0.185524
0.233599
0.280592
0.323218
0.371109
0.418523It means that the library only returns the player current position from 0.0 to 1.0 (not precise, in this video case it would be
0.0358617
to1.01173
).I was wondering. What is the best way to implement a slider for this?
Another thing is: I have to implement the events to the user so he can slider and set the video position, the library has a method I created called
setPosition(float)
that will also accepts a float position as percentage from0.0
to1.0
.Any ideas of how I can implement a
QSlider
to work with floats and work like aQProgress
with percentage, also allow it to be changeable by user mouse events to return me float points to set to the library (from0.0
to1.0
). -
Hi
Something likeclass DoubleSlider : public QSlider { Q_OBJECT public: DoubleSlider(QWidget *parent = 0) : QSlider(parent) { connect(this, SIGNAL(valueChanged(int)), this, SLOT(notifyValueChanged(int))); } signals: void doubleValueChanged(double value); public slots: void notifyValueChanged(int value) { double doubleValue = value / 10.0; emit doubleValueChanged(doubleValue); } };
Its a bit of cheat as internally its range 0-10 but we divide with 10 before emitting the value;
https://stackoverflow.com/questions/19003369/how-to-make-a-qslider-change-with-double-values
-
I don't understand why you connected the int to the float as I don't intend to use the int method from
QSlider
. The idea would be to connect the media player to set theQSlider
value directly. Idk, I'll see what I can do about that.The other thing is the range of the QSlider, I have to set it to 1.0 max as float, isn't it, but how?
-
@yugosonegi
Internally the range is ints
0-10
we divide by 10 and
get
0.1 to 1.0
and emit that as a signal. ( the new notifyValueChanged)
you can connect setPosition(float) to it and it should just work.you set max as 10. it will become 0.10
Well you can also make a value() that returns float and use that.