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. Deactivate scrollbar in QGraphicsScene whith Whell mouse.
Qt 6.11 is out! See what's new in the release blog

Deactivate scrollbar in QGraphicsScene whith Whell mouse.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.1k 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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

    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 BodenmannJ 1 Reply Last reply
    0
    • AlvaroSA AlvaroS

      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 BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by
      #2

      There you go: https://forum.qt.io/topic/68696/disabling-wheel-event-in-a-qgraphicsview

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      AlvaroSA 1 Reply Last reply
      1
      • Joel BodenmannJ Joel Bodenmann

        There you go: https://forum.qt.io/topic/68696/disabling-wheel-event-in-a-qgraphicsview

        AlvaroSA Offline
        AlvaroSA Offline
        AlvaroS
        wrote on last edited by
        #3

        @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

        Joel BodenmannJ 1 Reply Last reply
        0
        • AlvaroSA AlvaroS

          @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

          Joel BodenmannJ Offline
          Joel BodenmannJ Offline
          Joel Bodenmann
          wrote on last edited by Joel Bodenmann
          #4

          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)
          {
          	verticalScrollBar()->installEventFilter(this);
          	horizontalScrollBar()->installEventFilter(this);
          }
          

          I hope I got it right this time ;)

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved