disable horizontal scrolling in qTableWidget
-
wrote on 19 Aug 2021, 11:51 last edited by
Hello,
I am trying to make an app for touch screen devices but I have a qTablewidget where you can scroll because the widget is bigger then the screen you need horizontal scrolling, but the horizontal scrolling makes it annoying for the user to see the most important data (on the left) because sometimes you scroll accidentally to the right when scrolling vertically.
So my question is how to disable horizontal scrolling with the finger/wheel but it should be possible with the scroll bar?kind regards
Yina -
wrote on 19 Aug 2021, 13:50 last edited by JoeCFD
m_tableWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
also try if the code above does not help
m_tableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed );
m_tableWidget->horizontalHeader()->setStretchLastSection( true ); -
m_tableWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
also try if the code above does not help
m_tableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed );
m_tableWidget->horizontalHeader()->setStretchLastSection( true );wrote on 19 Aug 2021, 14:49 last edited byThe issue is that the width of the table is bigger than the width of the screen but if you scroll down it is quite easy to be accidentally on the right side of the table(because you scroll to the right) and then the user can't see the most important data on the left side of the table. that is why I want to disable horizontal scrolling but it should still be possible with the scrollbar to scroll horizontally.
kind regards
Yina -
The issue is that the width of the table is bigger than the width of the screen but if you scroll down it is quite easy to be accidentally on the right side of the table(because you scroll to the right) and then the user can't see the most important data on the left side of the table. that is why I want to disable horizontal scrolling but it should still be possible with the scrollbar to scroll horizontally.
kind regards
Yinawrote on 19 Aug 2021, 14:58 last edited by@Yina
If there isn't anything "inbuilt" to make a scrollbar respond to clicks but not wheel, and nothing to switch wheel off, I would have thought you'd want to look at getting at the low-level wheel events and ignoring them? Would aneventFilter()
let you distinguish between these inputs so you can filter out the wheel? -
wrote on 19 Aug 2021, 15:21 last edited by JoeCFD
As JonB said, disable horizontal scrolling in vertical scrolling event
and enable it when it is done.On touch screen, you check mouse press event
disable
mouse release event
enableor check the following code
bool TouchResetApplication::notify(QObject *receiver, QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: case QEvent::TouchCancel: return true; default: return QApplication::notify(receiver, event); } }
1/5