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. QScrollBar doesn't emit 'sliderMove(int)' signal when scrolling with mouse-wheel
Forum Updated to NodeBB v4.3 + New Features

QScrollBar doesn't emit 'sliderMove(int)' signal when scrolling with mouse-wheel

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.6k Views 1 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.
  • A Offline
    A Offline
    Absurd
    wrote on last edited by
    #1

    I am trying to catch any change in a QScrollBar that I have in a QScrollArea.

    Here's the smallest code segment that exhibits the issue:

    int Test::runApp(int argc, char* argv[]) {
        QApplication* app = new QApplication(argc, argv);
    
        QWidget* widget = new QWidget();
        widget->resize(1000, 1000);
    
        QScrollArea* sa = new QScrollArea();
        sa->setWidget(widget);
    
        connect(sa->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(notifySliderMove(int)));
        connect(sa->horizontalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(notifySliderMove(int)));
    
        QVBoxLayout* vbox = new QVBoxLayout();
        vbox->addWidget(sa);
    
        QDialog* dialog = new QDialog();
        dialog->setLayout(vbox);
    
        dialog->show();
    
        return app->exec();
    }
    
    void Test::notifySliderMove(int value) {
        qDebug() << "Signal captured, value = " << value;
    }
    

    c2bf9c96-5a21-4674-84bb-a0903c8146b6-image.png

    • When I scroll by clicking the up down arrows -----> signal is not emitted.
    • When I scroll with the mouse wheel -----> signal is not emitted.
    • When I scroll by clicking on the slider and dragging it -----> signal is emitted.

    Is this a known issue with the QScrollBar?
    If so, how can I workaround it? (I want to capture any change in the QScrollBar regardless of which of the three methods above was used)
    If not, what am I doing wrong?

    KroMignonK 1 Reply Last reply
    0
    • A Absurd

      I am trying to catch any change in a QScrollBar that I have in a QScrollArea.

      Here's the smallest code segment that exhibits the issue:

      int Test::runApp(int argc, char* argv[]) {
          QApplication* app = new QApplication(argc, argv);
      
          QWidget* widget = new QWidget();
          widget->resize(1000, 1000);
      
          QScrollArea* sa = new QScrollArea();
          sa->setWidget(widget);
      
          connect(sa->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(notifySliderMove(int)));
          connect(sa->horizontalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(notifySliderMove(int)));
      
          QVBoxLayout* vbox = new QVBoxLayout();
          vbox->addWidget(sa);
      
          QDialog* dialog = new QDialog();
          dialog->setLayout(vbox);
      
          dialog->show();
      
          return app->exec();
      }
      
      void Test::notifySliderMove(int value) {
          qDebug() << "Signal captured, value = " << value;
      }
      

      c2bf9c96-5a21-4674-84bb-a0903c8146b6-image.png

      • When I scroll by clicking the up down arrows -----> signal is not emitted.
      • When I scroll with the mouse wheel -----> signal is not emitted.
      • When I scroll by clicking on the slider and dragging it -----> signal is emitted.

      Is this a known issue with the QScrollBar?
      If so, how can I workaround it? (I want to capture any change in the QScrollBar regardless of which of the three methods above was used)
      If not, what am I doing wrong?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @Absurd said in QScrollBar doesn't emit 'sliderMove(int)' signal when scrolling with mouse-wheel:

      If not, what am I doing wrong?

      sliderMoved(int) is emitted when slider has been moved, so there is no bug IMHO.
      You should use signal valueChanged(int) to be aware about every changes, event if not caused by slider moving from user.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      5
      • A Offline
        A Offline
        Absurd
        wrote on last edited by
        #3

        Yes!
        valueChanged(int) has worked for me.
        Thanks.

        Although it's weird...
        When I use the the mouse-wheel to move the scroll bar I'd expect sliderMoved(int) to be emitted too. I mean, never mind that I used the mouse-wheel for that - the scroll bar has moved.

        artwawA Christian EhrlicherC 2 Replies Last reply
        0
        • A Absurd

          Yes!
          valueChanged(int) has worked for me.
          Thanks.

          Although it's weird...
          When I use the the mouse-wheel to move the scroll bar I'd expect sliderMoved(int) to be emitted too. I mean, never mind that I used the mouse-wheel for that - the scroll bar has moved.

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by artwaw
          #4

          @Absurd Hi, it is not weird. The documentation clearly states: This signal is emitted when sliderDown is true and the slider moves.
          When you use mouse wheel or arrow keys, sliderDown is not a case.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          2
          • A Absurd

            Yes!
            valueChanged(int) has worked for me.
            Thanks.

            Although it's weird...
            When I use the the mouse-wheel to move the scroll bar I'd expect sliderMoved(int) to be emitted too. I mean, never mind that I used the mouse-wheel for that - the scroll bar has moved.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Absurd said in QScrollBar doesn't emit 'sliderMove(int)' signal when scrolling with mouse-wheel:

            When I use the the mouse-wheel to move the scroll bar I'd expect sliderMoved(int) to be emitted too. I mean, never mind that I used the mouse-wheel for that - the scroll bar has moved.

            Maybe it's worth reading the documentation before assuming something and later complaining about that it does not work as expected?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • A Offline
              A Offline
              Absurd
              wrote on last edited by
              #6

              @Christian-Ehrlicher , no need for condescending attitude.
              I do read the documentation before making assumptions but I must have missed this one.

              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