In Qt, I have a QScrollArea that has some content in it that can scroll vertically but should never, ever be allowed to scroll horizontally. Even if I disable the H scrollbars from showing, a mouse that has a scroll wheel (or touch pad) that supports horizontal motion will make it move a little bit side to side.
Now, this may partly be a layout issue... but nothing is actually off the screen. It's probably a cop-out, but is there a way to just "lock" the scroll area from behind able to move horizontally at all?
scrollArea->verticalScrollBar()->setEnabled(false);
scrollArea->horizontalScrollBar()->setEnabled(false);
For your QScrollArea
you need filter QEvent::Wheel
in eventFilter
method or overload wheelEvent(QWheelEvent* event)
method.
Other way is create widget inherited from QWidget
with overloaded eventFilter
only and apply its filter to your scroll area:
scrollArea->viewport()->installEventFilter(someFilterWidget);
Did you try to set the scroll bar policy ?
myScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
http://qt-project.org/doc/qt-4.8/qabstractscrollarea.html#horizontalScrollBarPolicy-prop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With