Disabling Right and Left arrow shortcuts for the scrollbar?
-
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?
I think the most proper way of doing is reimplementing
keyPressEvent()
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. -
I think the most proper way of doing is reimplementing
keyPressEvent()
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.@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-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?
QGraphicsView
inherits fromQAbstractScrollArea
. Hence it is hierarchical. If you catch them within the view and don't propagate/forward them to the standard implementation ofQGraphicsView::keyPressEvent()
then the underlyingQAbstractScrollArea
will never get the key presses either. -
Hi,
Using an event filter would be cleaner
-
QGraphicsView
inherits fromQAbstractScrollArea
. Hence it is hierarchical. If you catch them within the view and don't propagate/forward them to the standard implementation ofQGraphicsView::keyPressEvent()
then the underlyingQAbstractScrollArea
will never get the key presses either.@Joel-Bodenmann Thank you for your reply. I've tested you suggestion and it seems to work.
-
Hi,
Using an event filter would be cleaner
@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; }
-
Hi,
Using an event filter would be cleaner
@SGaist said:
Using an event filter would be cleaner
You're right. I didn't think of that at all. Sorry!
-
It might be the scene that forwards the events to the scroll bar.