[Qt-interest] QgraphicsScene: best way to manage events
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri Nov 26 12:53:38 CET 2010
On 2010-11-26 Ross Ross Bencina wrote:
> Oliver Knoll wrote:
>
>> I don't think QGraphicsView/Scene "eats" such events before they
>> deliver it to your method. ...
> One reason I have not used event filtering is that QGraphicsScene doesn't
> (didn't?) provide a mechanism to intercept all QGraphicsSceneHoverEvents for the
> whole scene -- so I have a convoluted mechanism where the GraphicsItems notify
> my scene subclass of these events,
I am just doing my first steps with QGraphicsScene myself, but from what you write I understand the problem was that you did not get /all/ events on a "global QGraphicsScene" level, but instead the events were consumed by the individual QGraphicsItems? But isn't that the desired behaviour, analog to how events are handled in QWidget hierarchies?
The "most specific" widget/item gets the mouse event first (especially when talking about "mouse hover/move only" events), and only if that widget/item is *not* interested in that event it gets dispatched up the hierarchy, until the root element (the QGraphicsScene for example).
So that would be the use case then to install an "event filter", in order to prevent the "most specific" widget/item from receiving the event.
Or maybe your concrete use case was more complex or I don't understand the core problem you had ;)
> That said, I probably wouldn't have used the event filter mechanism anyway.
> I'm not a big fan of subclassing QObject for lightweight classes like Interactors
I agree that if there is no real need to subclass from QObject, well, then don't: in this case it is easier to expose the mouseMoveEvent() etc. methods and call them directly (also a bit more performant than re-sending events ;) But most often you need to subclass from QObject anyway, in order to have signal/slots working, and this is very likely the case for "tools" anyway (a paint tool might want to get informed whenever the "colour picker tool" has chosen another colour, as to bring up some artificial example), and "tools" usually remain in memory for the lifespan of the application, or at least for the lifespan of the "document" they are operating upon.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list