use space bar as shortcut

Feel free to ask any question here
Post Reply
fblue
Posts: 37
Joined: Thu Oct 25, 2018 9:00 am

use space bar as shortcut

Post by fblue »

Hello,
In my plugin, I'd like to use the space bar to invoke an action (ex: change the state of a toolButton in plugin). Is it possible to do that? and what if I use other shortcuts as "CTRL or ALT"?

Thank you in advance!
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: use space bar as shortcut

Post by daniel »

I believe you 'just' need to use the QShortcut object?
Daniel, CloudCompare admin
fblue
Posts: 37
Joined: Thu Oct 25, 2018 9:00 am

Re: use space bar as shortcut

Post by fblue »

Yes indeed.
But I've tried to set up QShortcut in my plugin by many ways, but nothing happens to the shortcut key.
The codes are like this:
QShortcut shortcut_pause = new QShortcut(QKeySequence(Qt::Key_F2), this);
connect(shortcut_pause, SIGNAL(activated()), this, SLOT(onShortcutTriggered()));

Then I found another post: http://www.cloudcompare.org/forum/viewt ... cut#p20715

So, as you said in the post, it's not possible to define custom shortcuts, in 'mainwindow' I suppose? Is it the reason why QShortcut didn't work in my plugin? or maybe there is something wrong somewhere in my program?

To precise: I've placed a break point in the beginning of the slot. But the program never goes into the slot when I press the key. I've also tried other keys, same problem.
daniel
Site Admin
Posts: 7711
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: use space bar as shortcut

Post by daniel »

I believe we were referring to user-defined shortcuts in this post.

In your case, I believe it's more a problem of context/focus. Do you add your shortcut to a dialog? Or is the user interacting with the 3D view? (because in this case, it's the 3D view that will process the shortcuts). You normally have to install a custom event filter if you want to catch the shortcuts (or other events).
Daniel, CloudCompare admin
Post Reply