Important: Please read the Qt Code of Conduct -

Deactivate scrollbar in QGraphicsScene whith Whell mouse.

  • Hello to everyone:

    I have a scene in a QGraphicsView.
    I have an scrollbars on it and this scrollbars works with wheel mouse but I would like to deactivate they work with that. I would like that they just work pressing in their arrows.

    How can I do that?

    Thanks a lot.

  • @Joel-Bodenmann Thaks for replying!!
    But It does not work for me.
    Because I have a wheel event where I use it for doing zoom in or zoom aout in scene.

    So I would like just remove wheel event for scrolling bars

  • Oh sorry, that's my bad. I just got up - should have paid more attention. Sorry!

    As far as I can tell the QScrollBar doesn't have a property to enable/disable the wheel handling either. So you would do the same thing but just for your scroll bars instead of your graphics view. However, that would require you to implement your own scroll bar subclass which might not be that fancy of a solution. Assuming that you already have a subclass of QGraphicsView you might want to consider to install an event filter on the scroll bars instead to filter out the wheel events for the scroll bars. Something along the lines of (untested):

    bool MyGraphicsView::eventFilter(QObject* object, QEvent* event)
        if (object == verticalScrollBar() && event->type() == QEvent::Wheel)  {
            return true;
        if (object == horizontalScrollBar() && event->type() == QEvent::Wheel)  {
            return true;
        return false;

    And in the constructor of the view subclass:

    MyGraphicsView::MyGraphicsView(QWidget* parent) : QGraphicsView(parent)

    I hope I got it right this time ;)

Log in to reply