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. Not getting Key and mouse events.

Not getting Key and mouse events.

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 3.2k 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.
  • A Offline
    A Offline
    at_pradeep
    wrote on last edited by
    #1

    Hi All,

    I am trying to build one sample application using QML+JavaScript and CPP.
    I an facing problem while running the application.

    My application does not receive any keyboard/key events also I am not getting proper mouse click events.
    I have one QML file in which i have two rectangles where I have key and mouse event listener code:

    @
    Rectangle
    {
    id: keyRect
    focus:true;
    color: "black"
    Keys.onPressed:
    {
    console.log("Keys.onPressed\n");
    }
    }

    Rectangle
    {
    id: mouseRect;
    focus:true;
    color: "blue"
    MouseArea
    {
    anchors.fill: parent
    acceptedButtons: Qt.LeftButton;
    onReleased:
    {
    console.log("Mouse Clicked\n");
    }
    }
    }
    @

    I am not getting any events in key listener "Keys.onPressed:" and for mouse event whenever I move mouse pointer on the mouse rectangle (without clicking) I get print "Mouse Clicked" print.

    This is my main.cpp file from where i am launching the first qml file which will start the application.

    @#include <QApplication>
    #include <QtDeclarative>
    #include <QDeclarativeView>
    #include <QVariant>

    QT_USE_NAMESPACE

    void* qmlMain(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QDeclarativeView view;
    view.setSource(QUrl::fromLocalFile&#40;"appEntry.qml"&#41;);
    
    app.setApplicationName("TestApp");
    app.setOrganizationName("Test");
    app.setOrganizationDomain("TestApp.com");
    
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.show();
    
    app.exec();
    
    return 0;
    

    }
    @

    Do i need to add anything else in above code to make it work.
    When i run this QML file with QML viewer it is working perfectly I am getting all the events.

    Thanks in advance.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zanes
      wrote on last edited by
      #2

      Hi,

      you can try the below line.

      Component.onCompleted:{ keyRect.focus = true }

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on last edited by
        #3

        Did you use sendEvent with keyEvent ?

        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