QKeySequence. How to re-define standard keyboard shotcut?
-
QKeySequence defines many QKeySequence::StandardKey {standard
keyboard shortcuts} to reduce the amount of effort required when
setting up actions in a typical application.Some key combinations (Ctrl+W in my case) are hard-coded in QKeySequence.cpp
The list of hard-coded key sequences are provided in the QKeySequence class documentation.
If the QAction is created with the same shot-cut then slot is not called and the following message is printed:
@QAction::eventFilter: Ambiguous shortcut overload: Ctrl+W@
How can I re-define Ctrl+W key combination?
-
Can you show code where you create yours shortcut?
-
I modified the examples\mainwindows\mdi
@MdiChild::MdiChild()
{
setAttribute(Qt::WA_DeleteOnClose);
isUntitled = true;
QKeySequence ks("Ctrl+W");
QAction* a = new QAction(this);
a->setShortcut(ks);
connect(a, SIGNAL(triggered()), this, SLOT(ctrlWPressed()));
addAction(a);
}void MdiChild::ctrlWPressed() {
qDebug("CtlW pressed");
}
@And the correspondent slot declaration in the header file.
-
The QMdiArea defines Ctrl+W as shortcut for closing a MDI subwindow.
Why do you want to change the standard behavior? You most probably are going to annoy your users...
-
[quote author="Volker" date="1322222474"]The QMdiArea defines Ctrl+W as shortcut for closing a MDI subwindow.
Why do you want to change the standard behavior? You most probably are going to annoy your users...[/quote]
I want to change the standard behavior because it is the end-user requirement :)
-
The shortcut is set in QMdiSubWindowPrivate::createSystemMenu() during the construction of a QMdiSubWindow, I doubt that you can remove it without having to patch Qt libs.