Results 1 to 8 of 8

Thread: QTabWidget: Shortcuts & Clicks

  1. #1
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTabWidget: Shortcuts & Clicks

    Hi.

    How can I catch a mouse click on a tab that is already the current tab? "currentChanged" is not emitted. :-/

    How can I pass shortcuts to widgets in pages that are not visible/selected in the tab widget?

    Bye

  2. #2
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    I solved the first questions/problem:

    Qt Code:
    1. MyTabWidget::MyTabWidget(QWidget *parent): QTabWidget(parent) {
    2. tabBar()->installEventFilter(this);
    3. ...
    4. }
    5.  
    6.  
    7. bool MyTabWidget::eventFilter(QObject *target, QEvent *event) {
    8. if(target == tabBar()) {
    9. if(event->type() == QEvent::MouseButtonPress) {
    10. /* do something here */
    11. }
    12. }
    13. return QTabWidget::eventFilter(target, event);
    14. }
    To copy to clipboard, switch view to plain text mode 

    But that shortcut problem is driving me mad. I've tried QShortcut, QAction, button shortcuts, event filters and keypress events ... Waaaaah

    Bye

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    Quote Originally Posted by youkai View Post
    But that shortcut problem is driving me mad. I've tried QShortcut, QAction, button shortcuts, event filters and keypress events ... Waaaaah
    QAction and button shortcuts are only sent to visible widgets so that's not the way to go.

    The simplest way (if compatible with your use case) is probably to place the action on the tabwidget and simply redirect the trigger to the proper widget.

    Otherwise putting an event filter on the tabwidget (from the widget in the tabs) should do but you'll have to do more processing to get it right(you cannot simply match a key sequence from a key event).
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    What kind of event arrives in case of a keyboard shortcut press? I've tried eventfilters to all page widgets already but I didn't find the "hook" event type.

    Bye

    Edit: Actions, stored in the subclass of QTabWidget will absolutely not recognized if the corresponding shortcut is pressed (key sequence).

    Another edit: I will try to catch QEvent::KeyPress in the event filter for all page widgets.

    Final edit here: The tabwidget does not get key events at all then, because it has no focus. Damn...
    Last edited by youkai; 19th July 2009 at 10:28.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    Have you tried changing the shortcutContext of these actions?
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    Yes, I have. An application-wide context should do it. But it doesn't work. I'm a little bit confused about using custom shortcuts or actions.

    Is it sufficient to store a list of actions in the custom QTabWidget and add them in the constructor like this?

    Qt Code:
    1. MyTabWidget::MyTabWidget(QWidget *parent): QTabWidget(parent) {
    2. _actions.append(new QAction(this));
    3. _actions.last()->setShortcut(Qt::Key_F1);
    4. _actions.last()->setShortcutContext(Qt::ApplicationShortcut);
    5. connect(_actions.last(), SIGNAL(triggered()), this, SLOT(doSomething()));
    6. }
    7.  
    8. void MyTabWidget::doSomething() {
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

    • Will "doSomething()" be executed if I hit F1 and the tabwidget has no focus?
    • Will a shortcut event be triggered to the tabwidget?
    • Should I use QShortcut instead of QAction?


    Bye

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    Quote Originally Posted by youkai View Post
    • Will "doSomething()" be executed if I hit F1 and the tabwidget has no focus?
    • Will a shortcut event be triggered to the tabwidget?
    • Should I use QShortcut instead of QAction?
    • It *should* as far as I understand the docs. However programming is an experimental discipline : test and see for yourself.
    • I am not sure how shortcut events are born and what they do during their short life but I guess the answer is yes.
    • Very unlikely. QShortcut is not a class meant to be used directly and I am not sure it will improve things if QAction does not work. In that case the only way would probably be to handle key events directly.
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget: Shortcuts & Clicks

    Quote Originally Posted by fullmetalcoder View Post
    • It *should* as far as I understand the docs. However programming is an experimental discipline : test and see for yourself.
    • I am not sure how shortcut events are born and what they do during their short life but I guess the answer is yes.
    • Very unlikely. QShortcut is not a class meant to be used directly and I am not sure it will improve things if QAction does not work. In that case the only way would probably be to handle key events directly.
    • I tried it - no success. :-( I think there is some kind of central place missing where a key-combo can be checked against present actions. The Qt framework has no idea that I put a list with actions in my tabwidget.
    • Thanks.
    • Thanks.


    Bye

    Edit: QWidget::addAction()
    Last edited by youkai; 20th July 2009 at 14:45.

Similar Threads

  1. Segment fault using a Qt plugin with QTabWidget
    By tarod in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2009, 10:27
  2. QTabWidget transparent background problem
    By destroyar0 in forum Qt Programming
    Replies: 10
    Last Post: 25th June 2009, 12:19
  3. Changing the background of QTabWidget
    By ike in forum Qt Tools
    Replies: 2
    Last Post: 7th November 2008, 13:43
  4. QTabWidget clicking problems after addTab()
    By DonSam in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2008, 08:28
  5. How do I add new tab to QTabWidget
    By pcmantinker in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2008, 04:24

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.