Unsolved Unable to pass QEvent from c++ to qml
-
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
-
QEvent is not recognised in QML. Just pass all the values required from C++ to QML method. Use those values at QML side.
-
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?
-
@JennyAug13 any constraints not to use MouseEvent QML type directly?
-
@Pablo-J.-Rogina It is interesting, i havent tried, how to use it?
-
@JennyAug13 mmm, I haven't tried myself. I think the magic of documentation and trial/error will be your friends...
-
You can't directly use the mouseevent as explained in the previous post.