c++ - Create QAction with shortcut, without inserting in menu -


#include "mainwindow.h" #include "ui_mainwindow.h" #include <qdebug> #include <cassert>  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);      qaction* = new qaction(this);     back->setvisible(true);     back->setshortcut(qkeysequence("ctrl+m"));     bool cres = connect(back, signal(triggered(bool)), this, slot(myslot()));     assert(cres); } 

in code tried catch ctrl+m key event. don't want put action in menu. connect returns true myslot never called. when action inserted in menu, shortcut works well. have done wrong?

qaction dormant until insert somewhere. vahancho has suggested, use qshortcut. need instantiate shortcut each top-level widget (window) want active. if have 5 top-level windows, you'll need 5 shortcuts, each having 1 of windows parent.

there no way use qshortcut global shortcut without gui. qshortcut active when associated widget has focus. widget top-level window.

system-global shortcuts subject of this question.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -