[SOLVED] QShortcut to slotToggleInspector
-
The web demo has a file menu which I've hidden. I want to replace the menu item to call @slotToggleInspector(bool)@ into a keyboard shortcut.
So I tried this, @new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));@ however this doesn't get called. Doing the same thing but for @Qt::Key_F1@ and calling @slotAboutApplication@ works fine. No errors.
Ideas?
-
Anybody?
This has really been bothering me and I still can't figure it out.
-
The only thing I can think of, is that something else is already using that shortcut (system perhaps), which is interfering with you doing the same.
-
[quote author="Andre" date="1333106992"]The only thing I can think of, is that something else is already using that shortcut (system perhaps), which is interfering with you doing the same. [/quote]
I thought this would be the case, however I've tried a whole bunch of shortcuts. I swapped ones that did work and they stopped working with that slot. -
@
new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));@
Ah, I note the error. What is the 'true' doing there? That is not allowed! This should give a warning at runtime...You should connect to a slot that does not take any arguments instead. I would use QAction in between your shortcut and the actual action as an abstraction. You connect your shortcut to the toggle() slot of QAction, and then use the toggeled(bool) signal to do the actual work. The action can also be put on a toolbar or in a menu or something like that.
-
Yes, but IMO, the following statement should have given a warning when the application running, tells that the slot doesn't exists.
@
new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));
@ -
Sorry for the late reply, I've been working on a few other things.
I noticed the error with the @true@ statement being in the code. I removed that promptly. I'll try the QAction method and see where that takes me.
-
Ah, now... My shortcut works when I have the File/Edit menu visible. If I hide it, my shortcut no longer works. Is there a way to avoid this behaviour?
-
I solved it by not needing the @toggle@ argument. Win!