PDA

View Full Version : Assign shortcut only



chiaminhsu
8th February 2013, 15:09
Hi,

BrushColorAction is a QAction assigned a shortcut (Ctrl + C) and is added in a menu.

brushColorAction = new QAction(tr("&Brush Color..."), this);
brushColorAction->setShortcut(tr("Ctrl+C"));
connect(brushColorAction, SIGNAL(triggered()),
this, SLOT(brushColorAct()));

void brushColorAct() { .. QColorDialog * dlg = new QColorDialog; .... }

If I want to remove the menu but keep the shortcut (Ctrl + C) to invoke the color dialog,
how to do it ? Thank your replay.

Santosh Reddy
8th February 2013, 17:31
If I want to remove the menu but keep the shortcut (Ctrl + C) to invoke the color dialog,
how to do it ?
Don't add to QMenu, Just create the QAction, set the shortcut, and add the action to dialog


MyDialog * dialog = new MyDialog;
brushColorAction = new QAction(tr("&Brush Color..."), dialog);
brushColorAction->setShortcut(tr("Ctrl+C"));
dialog->connect(brushColorAction, SIGNAL(triggered()), SLOT(brushColorAct()));
dialog->addAction(brushColorAction);

chiaminhsu
9th February 2013, 01:04
Thank you very much. It works, I also learn that addAction() more advancedly