I am trying to connect MouseArea mouse event with C++, But the QQuickMouseArea is private, so i could not fetch the signal.
Like this:
QObject::connect(mouseAreaObj, SIGNAL(released(QMouseEvent*)),
handlerObj, SLOT(handleEvent(QMouseEvent*)));
Is there any way to solve this?
And if not able, i wonder why Qt not allow us to access QQuickMouseArea.
Instead of listening to QQuickMouseArea signals, you can get it as a QObject and set your handlerObj as an event filter of your mouseAreaObj like this : mouseAreaObj->installEventFilter(handlerObj).
Then you'll need to implement eventFilter in your handlerObj.
Maybe something like this :
bool HandlerObject::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::MouseButtonRelease)
return handleEvent(static_cast<QMouseEvent*>(event));
else
return false;
}
I made the connection in qml mouseArea.clicked.connect(cppObject.onClicked) and then in C++ simply received a QObject* which has properties as expected:
void CppClass::onClicked(QObject *event) {
qDebug() << "clicked" << event->property("x").toInt();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With