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. Unable to pass QEvent from c++ to qml

Unable to pass QEvent from c++ to qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 940 Views
  • 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.
  • J Offline
    J Offline
    JennyAug13
    wrote on last edited by JennyAug13
    #1

    I have following code as follows inside my c++ class, I want to pass my QEvent::MouseMove to my qml file.

    Q_INVOKABLE void classMouseEvents::passMouseEvents(int x, QObject * btn)
    {
        QMouseEvent ev ( (QEvent::MouseMove), QPointF(100,100),
            Qt::NoButton,
            Qt::NoButton,
            Qt::NoModifier );
        qDebug()<< "x value is" << x ;
        qDebug()<< "Object is" << btn << "parent is" << btn->parent();
        //QMetaObject::invokeMethod(btn, "test", Q_ARG(QVariant, x));
        QMetaObject::invokeMethod(btn, "test", Q_ARG(QVariant, QEvent::MouseMove));
    }
    

    and I have my

    Q_DECLARE_METATYPE(enum QEvent::Type)
    

    I have my test function in my qml file

    classMouseEvents{
                id: demo
                objectName: "demoMouse"
             
                function test(MouseMove) {
                    console.log("Testslot QML " + MouseMove);
                }
            }
    

    But any way this will give an integer as it is an enum.But what should i give as an argument inside my function test? When I pass MouseMove, I am getting an enum of MouseMove which is 5.

    Previously when i was passing

    x
    

    I have given like this

    QMetaObject::invokeMethod(btn, "test", Q_ARG(QVariant, x));
    

    and in my qml file i had a function like as follows:

    function test(x) {
                  console.log("Testslot QML " + x);
              }
    

    And i can print the value of x .
    How can i do it with the events?

    And I want to use a setfilter to get the mouse events to my lower button which is hiding under an upper button, as i am unable to send a mouse event in above way!

    Can i do it as follows as shown in the followin link?

    https://stackoverflow.com/questions/36466415/qt-mouse-event-filter

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      QEvent is not recognised in QML. Just pass all the values required from C++ to QML method. Use those values at QML side.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JennyAug13
        wrote on last edited by
        #3

        Using those values, i am able to move my lower buttons sliding position but found that it is not a good way as the button movement is not smooth and also many issue during mouse press and mouse release signals. Would like to find another way by setting a filter and just pass mouse events to both the buttons and one of the button should ignore the events based on the set condition. But it is possible in qt, is it possible in c++ and later expose the same in qml?

        Pablo J. RoginaP 1 Reply Last reply
        0
        • J JennyAug13

          Using those values, i am able to move my lower buttons sliding position but found that it is not a good way as the button movement is not smooth and also many issue during mouse press and mouse release signals. Would like to find another way by setting a filter and just pass mouse events to both the buttons and one of the button should ignore the events based on the set condition. But it is possible in qt, is it possible in c++ and later expose the same in qml?

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @JennyAug13 any constraints not to use MouseEvent QML type directly?

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply
          2
          • Pablo J. RoginaP Pablo J. Rogina

            @JennyAug13 any constraints not to use MouseEvent QML type directly?

            J Offline
            J Offline
            JennyAug13
            wrote on last edited by
            #5

            @Pablo-J.-Rogina It is interesting, i havent tried, how to use it?

            Pablo J. RoginaP 1 Reply Last reply
            0
            • J JennyAug13

              @Pablo-J.-Rogina It is interesting, i havent tried, how to use it?

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @JennyAug13 mmm, I haven't tried myself. I think the magic of documentation and trial/error will be your friends...

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              2
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                You can't directly use the mouseevent as explained in the previous post.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                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