PDA

View Full Version : Prevent tab change from key press



khairulikhwan
8th January 2018, 07:10
Hi guys,

I would like to seek help regarding above topic. As of right now, whenver I press left or right arrow, this action will change the tab.

What I'm trying to achieve is to only allow the user to change the tab by clicking on the tab they want to show, instead of using the left or right arrow.

These arrows will be for the other action instead.

I have tried to override this function:

currentChanged(int index) for the QTabWidget, and try to get the QObject::sender (so that I can distinguish between the key press or the tab click), however, the sender is always the same (and I think it's always the parent that sends the signal).

Thank you in advance!

d_stranz
8th January 2018, 17:51
By the time you get the currentChanged() signal, it is too late. I think you will have to install an event filter for the tab widget (or its QTabBar) and intercept the left and right arrow key pressed events and then call ignore() for those. Don't know if this will work.

Another possibility is to derive a new QTabBar class and override the keyPressEvent() to ignore these keys. Use QTabWidget::setTabBar() to substitute your derived tab bar for the default one used in the tab widget.