Login

Qt mousePressEvent and mouseReleaseEvent fun!

This would have been good to know beforehand regarding mouse events…

Apparently in Qt, QGraphicsItem’s mouse events are a little different from the model I had in my head from Actionscript. In actionscript when a user uses the mouse to move over and then click on an MovieClip object these events occur (ignoring mouse movement events):

  1. onRollOver
  2. onPress
  3. onRelease
  4. onRollOut

In Qt it is not quite the same. If the QGraphicsItem accepts mouse clicks but is not movable or selectable then these are its events (again ignoring mouse movement events):

  1. hoverEnterEvent
  2. mousePressEvent
  3. hoverLeaveEvent

Notice in Qt there is not a mouse release event called. Qt does have a mouseReleaseEvent but it is only called if the item is movable or selectable (both not set by default).

This fact would have been good to know. I had been allowing QGraphicsItems to move during debuging and had been using mouseReleaseEvent as my click event. When I removed the debuging code suddenly I could not click my items, which was most distressing as it was only minutes away from my live demo. Luckly, I discovered this Qt fact, changed the event to mousePressEvent and got it all working.

How demos work as told on PHD comics.

Related posts:

  1. word 2007 spell checking inside tables
  2. Grabbing all QGraphicItems current viewable in a QGraphicView
This entry was posted in Qt Code and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">