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. Disabling Right and Left arrow shortcuts for the scrollbar?
Forum Updated to NodeBB v4.3 + New Features

Disabling Right and Left arrow shortcuts for the scrollbar?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 5.4k Views 2 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.
  • W Offline
    W Offline
    w.h.
    wrote on last edited by
    #2
    This post is deleted!
    1 Reply Last reply
    0
    • W w.h.

      I am triggering a function with a shortcut of Alt+Right and Alt+Left in a QGraphicsView. The scroll bar is moving as a result of pressing the Right and Left arrow keys. How do you disable the Right and Left arrow shortcuts for the scrollbar?

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

      I think the most proper way of doing is reimplementingkeyPressEvent() in your QGraphicsView and not reacting on the event when those keys are pressed. If anything but those keys are pressed just call the default implementation of that method.

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

      W 1 Reply Last reply
      0
      • Joel BodenmannJ Joel Bodenmann

        I think the most proper way of doing is reimplementingkeyPressEvent() in your QGraphicsView and not reacting on the event when those keys are pressed. If anything but those keys are pressed just call the default implementation of that method.

        W Offline
        W Offline
        w.h.
        wrote on last edited by w.h.
        #4

        @Joel-Bodenmann Thanks for your reply. How can I capture the keyPressEvent for the QAbstractScrollArea from within the GraphicsView's keyPressEvent? Is there any way to subclass the keyPressEvent for QAbstactScrollArea from within my custom GraphicsView class?

        Joel BodenmannJ 1 Reply Last reply
        0
        • W w.h.

          @Joel-Bodenmann Thanks for your reply. How can I capture the keyPressEvent for the QAbstractScrollArea from within the GraphicsView's keyPressEvent? Is there any way to subclass the keyPressEvent for QAbstactScrollArea from within my custom GraphicsView class?

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

          QGraphicsView inherits from QAbstractScrollArea. Hence it is hierarchical. If you catch them within the view and don't propagate/forward them to the standard implementation of QGraphicsView::keyPressEvent() then the underlying QAbstractScrollArea will never get the key presses either.

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

          W 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi,

            Using an event filter would be cleaner

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            W Joel BodenmannJ 2 Replies Last reply
            0
            • Joel BodenmannJ Joel Bodenmann

              QGraphicsView inherits from QAbstractScrollArea. Hence it is hierarchical. If you catch them within the view and don't propagate/forward them to the standard implementation of QGraphicsView::keyPressEvent() then the underlying QAbstractScrollArea will never get the key presses either.

              W Offline
              W Offline
              w.h.
              wrote on last edited by
              #7

              @Joel-Bodenmann Thank you for your reply. I've tested you suggestion and it seems to work.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Using an event filter would be cleaner

                W Offline
                W Offline
                w.h.
                wrote on last edited by w.h.
                #8

                @SGaist I like the idea of using an eventfilter. However, I can't seem to make a go of it. I installed an event filter on the horizontal scroll bar and the only events I seem to capture are paint events. What am I doing wrong? How do I capture the key press events from the horizontal scroll bar?

                //custom graphicsView
                horizontalScrollBar()->installEventFilter(this);
                
                
                bool myView::eventFilter(QObject *obj, QEvent *event)
                {
                     if(obj == horizontalScrollBar() && event->type() == QEvent::KeyPress)
                      {
                           qDebug()<<"Scroll Bar Key press event";
                
                            return true;
                       }
                        if(obj == horizontalScrollBar() && event->type() == QEvent::Paint)
                      {
                           qDebug()<<"Scroll Bar Paint event";
                       }
                
                    return false;
                }
                
                
                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Using an event filter would be cleaner

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

                  @SGaist said:

                  Using an event filter would be cleaner

                  You're right. I didn't think of that at all. Sorry!

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

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    It might be the scene that forwards the events to the scroll bar.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    W 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      It might be the scene that forwards the events to the scroll bar.

                      W Offline
                      W Offline
                      w.h.
                      wrote on last edited by w.h.
                      #11
                      This post is deleted!
                      1 Reply Last reply
                      0

                      • Login

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