Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-63511

QSlider should be able to ensure its value increased by 1 step per 1 mouse wheel tick

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.8.0
    • None
    • Windows 7, Kubuntu 17, Qt 5.5 - 5.8

    Description

      I have a QSlider with boundaries [-50;50], step = 1, and page step = 5.

      Unfortunately, I got complains from users that my slider is hard to use with mouse wheel as it increase/decrease by 3 instead of 1 per each wheel tick. The problem isn't affect trackpads (value increased by 1 ) - only mouse users. I found out, that 3 lines per wheel tick - is a default system setting for Ubuntu and Windows for a regular mouse.

      My suggestion is to add functionality to QSlider that allows it to ignore or override system mouse wheel sensitivity value. Currently I've achieved desired behaviour (slider value changes by 1 even if wheel setting is 3 lines per wheel turn) with interception of its wheel event and following code:

       

      int sum_y = 0;

      bool MyWidget::eventFilter(QObject *obj, QEvent *event)
      {
          if (obj && event && event->type() == QEvent::Wheel) {
              QWheelEvent* e = (QWheelEvent*) event;
              if (e->modifiers() == Qt::NoModifier) {
                  const QPoint& angleDelta = e->angleDelta();
                  if (!angleDelta.isNull()) {
                      sum_y += angleDelta.y();
                      if (abs(sum_y) >= 30) {
                          QSlider* slider= (QSlider*) obj;
                          int dy = (sum_y > 0) ? slider->singleStep() : -1 *slider ->singleStep();
                          slider->setValue(slider->value() + dy);
                          sum_y = 0;
                          e->accept();
                          return true;
                      }
                  }
              }
          }
          return false;
      }

       

      Here static sum_y is needed to avoid making trackpad's behaviour too sensitive.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard Richard Moe Gustavsen
            truf Alexander Trufanov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes