[SOLVED] childMouseEventFilter QQuickItem receive mouse events
-
Hello,
i have a little problem. I've wrote my own class derived from QQuickItem. To handle mouse events i implement childMouseEventFilter.
c++
@
childMouseEventFilter(QQuickItem * item, QEvent * event) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
qDebug("mouse press");
break;
}
case QEvent::UngrabMouse:
qDebug("ungrab");
break;
case QEvent::MouseButtonRelease: {
qDebug("mouse release");
break;
}
default:
break;
}
return false;
}
@qml
@
Rectangle {
anchors.fill: parent
color: '#ff0000'
RippleBehavior {
color: '#ffffff'
anchors.fill: parent
Text {
anchors.fill: parent
text: "test"
// MouseArea {
// anchors.fill: parent
// onClicked: {
// console.log("clicked");
// }
// }
}
}
}
@So my problem is MouseButtonRelease is never thrown. If i use MouseArea everything is fine but without, directly after the MouseButtonPressed event i get the UngrabMouse event. What can i do, anybody an idea?
Thx for any reply
-
Alright, i've solved my problem. The trick here is to call the ungrab function from the item that trown the ungrab event.
@
childMouseEventFilter(QQuickItem * item, QEvent * event) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
this->_addRipple(mouseEvent->x(), mouseEvent->y());
break;
}
case QEvent::UngrabMouse:
qDebug("ungrab");
item->grabMouse(); // this line here did the magic
break;
case QEvent::MouseButtonRelease: {
RippleNode node = static_cast<RippleNode>(this->_node->lastChild());
node->fadeOut();
break;
}
default:
break;
}
return false;
}
@