PDA

View Full Version : QAction shortcut



^NyAw^
3rd December 2009, 18:53
Hi,



m_pqAction = new QAction(tr("Lock"),this);
m_pqAction ->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7));
connect(m_pqAction ,SIGNAL(triggered()),this,SLOT(lock()));
The connect returns true but the SLOT is never called.
Have I to add the action on a QToolBar to let it work? The other actions added to the QToolBar work well but this action have to not be shown.

Thanks,

caduel
3rd December 2009, 20:35
you need to add the action to a widget, otherwise it won't work.
Try calling QAction::setVisible() to hide it afterwards (if you add it to the toolbar). You can add it to the window itself, then you dont have to hide it, btw.

HTH