Results 1 to 2 of 2

Thread: Prevent tab change from key press

  1. #1
    Join Date
    Jan 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Prevent tab change from key press

    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!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Prevent tab change from key press

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QTabWidget - prevent change of tab without disabling tabs
    By ashtray4241 in forum Qt Programming
    Replies: 4
    Last Post: 23rd September 2016, 11:12
  2. Prevent window size change when font size changes
    By quimnuss in forum Qt Programming
    Replies: 0
    Last Post: 3rd September 2015, 14:17
  3. Replies: 6
    Last Post: 21st August 2010, 21:09
  4. Replies: 1
    Last Post: 11th December 2009, 17:21
  5. How to prevent table header from font change.
    By kenny_isles in forum Qt Tools
    Replies: 1
    Last Post: 14th February 2007, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.