[Qt-interest] QgraphicsScene: best way to manage events
Ross Bencina
rossb-lists at audiomulch.com
Fri Nov 26 12:09:56 CET 2010
Oliver Knoll wrote:
> I don't think QGraphicsView/Scene "eats" such events before they deliver
> it to your method. Unless off course some other widget in your app has
> focus and already consumes a shortcut, for example, or the aforementioned
> event filter is installed.
<
I just had a look at my code:
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, and it then the scene dispatches
them to active Interactors (this might have been fixed now, QGraphicsScene
was very new when I started using it) My comment says:
// HACK: it would be really handy to have access to these events
// as they are dispatched so that I didn't have to implement
// the hackneyed dispatch scheme here.
So it wasn't that QGraphicsScene "eats" events -- just that I couldn't work
out a way to intercept them.
My GraphicsScene subclass also has another mechanism that dispatches
synthetic mouse move events to my Interactors while drag-and-drop is in
progress -- this allows me to do things like render QGraphicsItems that
follow the cursor during an externally initiated drop operation that share
the same Interactor code as drag-drop within the graphics scene.
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 have a lot of Interactor subclasses, most of them get
created when the mouse is clicked and deleted when it's released -- having
all the QObject overhead is too heavy-weight for my liking.
Ross.
More information about the Qt-interest-old
mailing list