Qt - Delete shortcut - Ambiguous overload of shortcuts

Background Information: I am trying to create an application using Qt. This application has QMdiArea and a child window. My child window will have a menu that can be integrated into QMdiArea or shared and attached to the child himself. Although, this is a little more detailed than necessary ...

Problem: I would like my child widget to have a menu labeled "CTRL + W". But, since I'm using QMdiArea, the shortcut is already in use, calling:

QAction :: eventFilter: Undefined label overload: Ctrl + W

How can I get rid of this shortcut and require it inside my child widget?

Update: Here is what I tried with no luck:

class MDI : public QMdiArea
{
    Q_OBJECT
    private:
    bool event(QEvent *tEvent)
    {
        if (tEvent->type() == QEvent::KeyPress)
        {
            QKeyEvent* ke = static_cast<QKeyEvent*>(tEvent);
            if (ke->key()== Qt::Key_W && ke->modifiers() & Qt::ControlModifier)
            emit KeyCW();
            return true;
        }
        return QMdiArea::event(tEvent);
    }
public:
signals:
    void KeyCW();
};

, - , change Qt::Key_W to Qt::Key_L. - . W . event QMainWindow, eventFilter QMdiArea. , - , QMdiArea.

+5
5
0

QMdiSubWindow , Qt::CustomizeWindowHint .

QMdiSubWindow *subWindow2 = mdiArea.addSubWindow(internalWidget2, 
                                                 Qt::Widget | Qt::CustomizeWindowHint | 
                                                 Qt::WindowMinMaxButtonsHint);
+2

QMdiArea reimplement keyPressEvent(). .

  void keyPressEvent(QKeyEvent* event){

    if(event->key() == Qt::Key_W and event->modifiers() & Qt::ControlModifier){
      // handle it
    }else{
      return QMdiArea::keyPressEvent(event);
    }
  }

. , , .

bool CustomMdiArea::eventFilter(QObject *object, QEvent *event){
     if(object == yourChildWindow && event->type() == QEvent::KeyPress) {
         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
         if(keyEvent->key() == Qt::Key_W and keyEvent->modifiers() & Qt::ControlModifier) {
             //handle it
             return true;
         }else{
             return false;
         }
     }
     return false;
 }
0

, . Qt::WidgetShortcut, . :

  closeAction = new QAction(tr("&Close"), this);
  closeAction->setShortcut(Qt::CTRL|Qt::Key_W);
  closeAction->setShortcutContext(Qt::WidgetShortcut);
  connect(closeAction, SIGNAL(triggered()), mdiArea, SLOT(closeActiveSubWindow()));
0

:

for( QAction *action : subWindow->systemMenu()->actions() ) {
    if( action->shortcut() == QKeySequence( QKeySequence::Close ) ) {
        action->setShortcut( QKeySequence() );
        break;
    }
}
0

All Articles