Unsolved QShortcut and fullscreen QWidget issue
-
I have a
QMainWindow
with multipleQDockWidget
s. Those dock widgets hold differentQWidget
based classes in them. For the sake of context: One of the docks contains a text editor widget. The text editor obviously uses keyboard input to modify the text content. However, that widget also usesQShortcut
s to toggle the visibility of the search bar (Ctrl+F) and similar.What I am trying to add to my application is a
QShortcut
that allows the user making the currently focusedQDockWidget
become fullscreen temporarily. I added a newQShortcut
and the corresponding slot-code to theQMainWindow
class. So far everything works great: Pressing the key combination Ctrl+Alt+F will make the dock become fullscreen, pressing it again will put it back where it was before.
However, my problem is that once the dock became fullscreen and I start clicking and typing around in the dock's widget (eg. that text editor), the key combination to make the dock leave the fullscreen mode no longer works.Does anybody have an idea what the issue is? The
QShortcut
in theQMainWindow
has been configured to useQt::ApplicationShortcut
so I don't believe that it's a focus problem - yet the slot simply never gets called.QShortcut* shortcutToggleFullscreenCurrentDock = new QShortcut(this); shortcutToggleFullscreenCurrentDock->setContext(Qt::ApplicationShortcut); shortcutToggleFullscreenCurrentDock->setKey(ShortcutSequences::fullscreenCurrentDock()); connect(shortcutToggleFullscreenCurrentDock, &QShortcut::activated, this, &MainWindow::dockToggleShowFullscreen);
I'd be thankful for any kind of hint/tipp.
-
@Joel-Bodenmann said in QShortcut and fullscreen QWidget issue:
connect(shortcutToggleFullscreenCurrentDock, &QShortcut::activated, this, &MainWindow::dockToggleShowFullscreen);
try also (additionally) to connect to the
activatedAmbiguously()
signal -
Hi,
I assume a text editor (that has the focus) thinks that all keyboard events (like pressing character keys or CTRL-C, CTRL-V) are meant for it and swallows them. It does not delegate them to the parent widget.
-Michael. -
@raven-worx said in QShortcut and fullscreen QWidget issue:
try also (additionally) to connect to the activatedAmbiguously() signal
That appears to be the trick! I haven't tested it with all the possible corner cases but so far it appears to be working nicely! Thank you very much for your help.
@m.sue said in QShortcut and fullscreen QWidget issue:
I assume a text editor (that has the focus) thinks that all keyboard events (like pressing character keys or CTRL-C, CTRL-V) are meant for it and swallows them. It does not delegate them to the parent widget.
That is correct - but what do I have to do in order to still set up a truly application wide shortcut?
I would have assume that shortcuts that the text editor doesn't know (eg. ALT + CTRL + F in my case) will simply be ignored and thus forwarded to the parent.