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
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
I solved the first questions/problem:
Qt Code:
tabBar()->installEventFilter(this); ... } if(target == tabBar()) { /* do something here */ } } }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
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
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.
Have you tried changing the shortcutContext of these actions?
Current Qt projects : QCodeEdit, RotiDeCode
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:
_actions.last()->setShortcut(Qt::Key_F1); _actions.last()->setShortcutContext(Qt::ApplicationShortcut); connect(_actions.last(), SIGNAL(triggered()), this, SLOT(doSomething())); } void MyTabWidget::doSomething() { ... }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
- 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
- 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.
Bookmarks