Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create a video player slider seeker with QSlider

Create a video player slider seeker with QSlider

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yugosonegi
    wrote on last edited by yugosonegi
    #1

    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/signal positionChanged returns me this:

    0.00329063
    0.0478329
    0.0957256
    0.14266
    0.185524
    0.233599
    0.280592
    0.323218
    0.371109
    0.418523

    It 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 to 1.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 from 0.0 to 1.0.

    Any ideas of how I can implement a QSlider to work with floats and work like a QProgress with percentage, also allow it to be changeable by user mouse events to return me float points to set to the library (from 0.0 to 1.0).

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Something like

      class 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

      Y 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Something like

        class 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

        Y Offline
        Y Offline
        yugosonegi
        wrote on last edited by yugosonegi
        #3

        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 the QSlider 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?

        mrjjM 1 Reply Last reply
        0
        • Y yugosonegi

          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 the QSlider 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?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved