Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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?



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



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



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


  • Lifetime Qt Champion

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



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


Log in to reply