Reputation: 41
Currently, I am working on an editor program. I want to assign three shortcut keys (QKeySequence::Cut), (QKeySequence::Copy) and (QKeySequence::Paste) to my customized functions. However, it does not work as my expectation.
For testing, I open the "Application Example" from QtCreator. Then, I try to disable all the shortcut keys as following:
//cutAct->setShortcuts(QKeySequence::Cut);
connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
//copyAct->setShortcuts(QKeySequence::Copy);
connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy()));
pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
//pasteAct->setShortcuts(QKeySequence::Paste);
Surprisingly, the shortcut keys still working as before.
Another test is that:
Then, my result is
Any advice are welcome. Thank you very much.
Upvotes: 3
Views: 1816
Reputation: 41
I have found the way to override the default shortcut, thanks to the code of Sigil.
I use the following code:
Delacre a new action in header:
QShortcut &m_Paste1;
Then, in the constructor of class:
m_Paste1(*(new QShortcut(QKeySequence(QKeySequence::Paste), this, 0, 0, Qt::WidgetShortcut))),
Finally, connect it to your own slot
connect(&m_Paste1, SIGNAL(activated()), this, SLOT(paste()));
Upvotes: 1