Enter and Leave events using QQuickItem
-
Hi,
I want to highlight my items when the mouse moves over them. So I need a way to know when the mouse enters my item and when it leaves. With QWidget I would use EnterEvent and LeaveEvent. But these nice functions don't exist for QQuickItem.
I tried overloading HoverEnterEvent and HoverLeaveEvent, but they only partially give the result I need. When I move the mouse for a parent to a child, I still get hover events from the parent.
Any help is appreciated.
-
You can do this easely with states, I've used it myself to render an item with opacity when the mouse is held over it:
@
MouseArea {
id: delegateImgMouseArea;
anchors.fill: parent;
hoverEnabled: true;
}states: State { when: delegateImgMouseArea.containsMouse; PropertyChanges { target: delegateImg; opacity: 1; } }
@
Edit: please use @ tags around code sections; Andre
-
-
[quote author="Zamx" date="1341403462"]I tried overloading HoverEnterEvent and HoverLeaveEvent, but they only partially give the result I need. When I move the mouse for a parent to a child, I still get hover events from the parent.[/quote]This is the default behaviour for QHoverEvent, which can be disabled by setting the Qt::WA_NoMousePropagation attribute.
-
[quote author="diro" date="1341460818"]Zamx, will you need a C++ solution?
With MouseArea, you can call a C++ function, I think it is a cleaner and easier solution.[/quote]I'm using C++, because creating a lot of custom QQuickItem's and I want them all to have the same mouse behaviour.
[quote author="Lukas Geyer" date="1341468186"]This is the default behaviour for QHoverEvent, which can be disabled by setting the Qt::WA_NoMousePropagation attribute.[/quote]
Can I use Qt::WA_NoMousePropagation? Because then I need to call setAttribute( ... ) which QQuickItem doesn't have.
-
Well, that's actually right. Do you mind filing a "bug report":http://qt-project.org/doc/qt-5.0/bughowto.html?
-
[quote author="Lukas Geyer" date="1341473151"]Well, that's actually right. Do you mind filing a "bug report":http://qt-project.org/doc/qt-5.0/bughowto.html?[/quote]