[Qt-qml] QDeclarativeItem subclasses and mouse events
Jan Ekholm
jan.ekholm at smultron.net
Mon Aug 2 20:55:58 CEST 2010
Hi,
I was recommended to make a C++ QDeclarativeItem subclass for my game map
tiles to get better performance. This worked well and the class was easy to
implement, register and get to work. However, I can't seem to get mouse
press/release events to work, whatever I do the events aren't relayed to my
items. The methods I try are:
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
I guess I can make a MouseArea per item as I had before with my pure QML
solution, but it's not ideal. The items are not rectangles in shape and it's
not possible to have custom shapes for MouseArea.
I see that the shape() method is called for the correct C++ item, so
apparently something checks wether the mouse was pressed inside the C++ item,
but I never get any event.
Probably there's something trivial I'm missing here? I've looked through all
the demos and examples, but none of the C++ items are interactive that I can
see.
Any hints as to where my failure to grok stuff would be?
Kind regards,
Jan Ekholm
--
Five exclamation marks, the sure sign of an insane mind.
-- Terry Pratchett, Reaper Man
More information about the Qt-qml
mailing list