Action Shortcut Doesn't Work in QML When Combining Qt Widgets and QML with QWidget::createWindowContainer()

  • I started the example to create a Qt GUI application with a UI class derived from QMainWindow and a Qt Designer form.
    In the implementation of the UI class in mainwindow.cpp, I created a QQuickView and then call QWidget::createWindowContainer(), passing in the view and the parent widget. This returns a QWidget that we can add to the UI layout. Shown below is the code in mainwindow.cpp.

    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        setWindowTitle(tr("Tab Dialog"));
        _qmlView        = new QQuickView();
        _qmlWidget      = QWidget::createWindowContainer(_qmlView);

    I created a simple QML file which displays a rectangle and when user click right mouse button the Menu will be appeared.

    Rectangle {
        id: main
        width: 600
        height: 300
            Menu {
                id: menu
                title: "Edit";
                MenuSeparator { }
                MenuItem { action: copyAction; shortcut: StandardKey.Copy }
                MenuItem { action: pasteAction }
                MenuItem { action: selectAllAction }
                MenuSeparator { }
                MenuItem { action: deleteAction }
                MenuItem { text: "Delete all" }
                MenuSeparator { }
                MenuItem { text: "Auto arrange" }
        Action {
                id: copyAction
                text: "&Copy"
                shortcut: StandardKey.Copy
                iconName: "edit-copy"
                onTriggered: console.log("Ctrl+C is pressed")
        Action {
                id: pasteAction
                text: "&Paste"
                shortcut: StandardKey.Paste
                iconName: "edit-paste"
                onTriggered: console.log("Ctrl+V is pressed")
        Action {
                text: "&SellectAll"
                shortcut: StandardKey.SelectAll
                iconName: "edit-selectAll"
                onTriggered: console.log("Ctrl+A is pressed")
        Action {
                id: deleteAction
                text: "&Delete"
                shortcut: StandardKey.Delete
                iconName: "edit-delete"
                onTriggered: console.log("Delete is pressed")
            anchors.fill : parent;
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onClicked: {
                if(mouse.button === Qt.RightButton){

    But my question is when I click right mouse button, shortcut doesn't work after that but then I minimize the windows and then maximize shortcut will be activated again. Whenever I click right mouse button, shortcut will be disable. WHY?

  • Moderators


    QQuickView + QWidget::createWindowContainer() has known issues. Try QQuickWidget instead.

  • @JKSH Thank you very much for the prompt reply. I tried it, ShortCut Action doesn't work in QQuickWidget at all.

  • Moderators

    @beh_zad said:

    I tried it, ShortCut Action doesn't work in QQuickWidget at all.

    Interesting... I tried it too, and you're right: The keyboard shortcuts don't trigger at all. I think it's a bug. Would you like to report this to ?

    You can also subscribe to the Interest mailing list and ask the Qt engineers if they have a workaround for this issue.

  • @JKSH Yes, I will do it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.