November 24, 2011

blex blex
Lab Rat
192 posts

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:

  1. QAction::eventFilter: Ambiguous shortcut overload: Ctrl+W

How can I re-define Ctrl+W key combination?

 Signature 

————————————

Oleksiy Balabay

5 replies

November 24, 2011

RazrFalcon RazrFalcon
Lab Rat
124 posts

Can you show code where you create yours shortcut?

 Signature 

QT != Qt
Gentoo + KDE

November 25, 2011

blex blex
Lab Rat
192 posts

I modified the examples\mainwindows\mdi

  1. MdiChild::MdiChild()
  2. {
  3.     setAttribute(Qt::WA_DeleteOnClose);
  4.     isUntitled = true;
  5.     QKeySequence ks("Ctrl+W");
  6.     QAction* a = new QAction(this);
  7.     a->setShortcut(ks);
  8.     connect(a, SIGNAL(triggered()), this, SLOT(ctrlWPressed()));
  9.     addAction(a);
  10. }
  11.  
  12. void MdiChild::ctrlWPressed() {
  13.     qDebug("CtlW pressed");
  14. }

And the correspondent slot declaration in the header file.

 Signature 

————————————

Oleksiy Balabay

November 25, 2011

Volker Volker
Ant Farmer
5428 posts

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…

November 25, 2011

blex blex
Lab Rat
192 posts

Volker wrote:
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…

I want to change the standard behavior because it is the end-user requirement :)

 Signature 

————————————

Oleksiy Balabay

November 25, 2011

Volker Volker
Ant Farmer
5428 posts

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.

 
  ‹‹ Pinch Simulation without Multi touch device      Qt static with MYSQL ››

You must log in to post a reply. Not a member yet? Register here!