[Kde-games-devel] accept() mouse events?
Stefan Majewsky
kdemailinglists at bethselamin.de
Tue Jun 22 23:04:26 CEST 2010
On Tuesday 22 June 2010 19:33:38 Parker Coates wrote:
> Personally, I think it's generally a good idea to accept() events when
> appropriate. (As far as I know, explicitly ignore()ing an event is
> almost never necessary outside of some advanced use cases.)
An event is either accepted or ignored. It starts in the ignored state,
because nobody has accepted it yet. Starting with the innermost widget
matching the activation conditions, the event is sent to all possible
recievers until someone accepts it.
Therefore, the only useful case of ignore()ing an event is probably when you
want to use the base class implementation of the event handler, but
specifically ignore some special events to disable some features (though this
is not recommended because you come to rely on how the base class actually
implements its features).
> So basically, don't bother losing any sleep over it, but if you're
> feeling ambitious then it certainly wouldn't hurt to add a few
> accept() calls.
Up to now, I have also added accept() calls only when things were not working
without them (just because of laziness). These cases most often appeared in
QGraphicsView code, and there is a reason for that.*
With QWidget, it seems that if an event is not accepted by any involved
widget, Qt does just assume that it was accepted by the innermost widget, so
for mouse events, it just grabs the mouse for this widget and continues to
send related events to this widget. It is therefore sufficient to only
implement the mouseMoveEvent() if you have nothing to do in press/release.
The case is different for QGraphicsItems: Besides configuring the mouse
interface with QGI::setAcceptedMouseButtons, one has to be careful about
accepting all wanted mousePressEvents(), because there is always one instance
that will accept all otherwise ignored mouse events, the viewport.
Greetings
Stefan
* All of this is not formally proven, but derived from my personal experience.
P.S. This might make for a good blog article. Any takers?
More information about the kde-games-devel
mailing list