Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Action Shortcut Doesn't Work in QML When Combining Qt Widgets and QML with QWidget::createWindowContainer()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    beh_zad
    wrote on last edited by
    #1

    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) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        setWindowTitle(tr("Tab Dialog"));
    
        _qmlView        = new QQuickView();
        _qmlView->setSurfaceType(QSurface::OpenGLSurface);
        _qmlView->setSource(QUrl("TMainView.qml"));
        _qmlView->setResizeMode(QQuickView::SizeRootObjectToView);
        _qmlWidget      = QWidget::createWindowContainer(_qmlView);
    
        ui->horizontalLayout->addWidget(_qmlWidget);
    }
    

    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
    
        Rectangle{
    
            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 {
                id:selectAllAction
                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")
            }
    
        MouseArea{
            anchors.fill : parent;
            acceptedButtons: Qt.LeftButton | Qt.RightButton
    
            onClicked: {
                if(mouse.button === Qt.RightButton){
                    menu.popup();
                }
            }
        }
    }
    

    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?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

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

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beh_zad
        wrote on last edited by
        #3

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

        JKSHJ 1 Reply Last reply
        0
        • B beh_zad

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

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @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 https://bugreports.qt.io/ ?

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

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          B 1 Reply Last reply
          0
          • JKSHJ JKSH

            @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 https://bugreports.qt.io/ ?

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

            B Offline
            B Offline
            beh_zad
            wrote on last edited by
            #5

            @JKSH Yes, I will do it.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved