Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable horizontal scrolling in QScrollArea completely, not just the bars

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?

like image 484
Adam Haile Avatar asked Oct 18 '12 14:10

Adam Haile


3 Answers

scrollArea->verticalScrollBar()->setEnabled(false);
scrollArea->horizontalScrollBar()->setEnabled(false);
like image 111
Angel.Risteski Avatar answered Oct 06 '22 11:10

Angel.Risteski


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);
like image 27
fasked Avatar answered Oct 06 '22 12:10

fasked


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

like image 45
alberthier Avatar answered Oct 06 '22 13:10

alberthier