QSlider mouse direct jump

后端 未结 12 1801
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 16:27

Instead of stepping when the user clicks somewhere on the qslider I want to make the slider jump to that position. How can this be implemented ?

12条回答
  •  不知归路
    2020-12-23 16:58

    i have been trying and searching this on net and was expecting Qt for a smarter way doing this, unfortunately there was not big help (may be i was not searching properly )

    well i have done this in Qt creator:

    1. Add an eventFilter in header ( takes QObject and QEvent as argument ) (bool return type)
    2. Initialize in constructor ..for eg .. if ur slider is HSlider then ui->HSlider->installEventFilter(this);
    3. In the defination :

      a. check if the object is your slider type something like : ui->HSlider == Object

      b. Check for mouse click event something like : QEvent::MouseButtonPress == event->type

      c. if the above all passes means u have got mouse event on the slider do something like : in definition : ui->HSlider->setValue( Qcursor::pos().x() - firstval ); return QMainWindow::eventFilter(object, event);

    Note: fistVal : can be taken out by printing the cursur position at 0 = initial position of the slider ( with help of QCursor::pos().x() )

    hope this helps

提交回复
热议问题