I have a subclass of QGraphicsItem
and I want to track mouse position every time I hover the mouse on that Item alone and it should give the relative position to the QGraphicsItem
. I know, how to handle this when there is QWidget
(using QWidget.setMouseTracking
) and QMainWindow
(by installing event filters), but I cant figure out how to do it for QGraphicsItem
. The mouse move event is only triggered, when there is mouse press event, but that's not what is want. I want a trigger whenever I hover on that QGraphicsItem
. Please provide your suggestions
You will want to use my_item.setAcceptHoverEvents(True)
to enable mouse move events without the mouse press event.
Note, this will not trigger a mouseMoveEvent
but will instead trigger a hoverMoveEvent
(along with hoverEnterEvent
and hoverLeaveEvent
when you initially move the mouse over or off the QGraphicsItem
respectively. So make sure you override this method in your subclass of QGraphicsItem
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.