Important: Please read the Qt Code of Conduct -

Focus of shortcut

  • I've created two windows, one is the main window, the other one is the child window of main window. I've set window modality of the child window. On the child window, the menu bar of main window was set to disabled, but when I press the shortcut "Command + V" the main window menu bar responded(it showed that the menu Edit has been activated) , there is noting pasted on the child window. But if I right click and select the Paste, it works well.
    If I click the menu bar then paste on child window, the shortcut work well.
    So, I am wondering whether the child window doesn't get the shortcut focus. If there any one help me to solve this issue, thanks.

    Following are the code of child window.

    childWindow->setWindowFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::WindowTitleHint); 

    Best Regards

  • Lifetime Qt Champion


    IIRC, you have to associate your action to each widget it should act with. You can do that with QWidget::addAction.

    Hope it helps

  • Hi SGaist,

    Thanks for your reply.

    I don't think it caused by missing QWidget::addAction, because sometimes the shortcuts works well.
    I've used the default shortcuts of widget(copy, paste and cut). It's strange that after the child window lunched the shortcuts don't work, but after click the Main window's menu bar(even the button in menu is disabled), the shortcuts works well. So i suspected whether there is the shortcut focus.

Log in to reply