Qt-jambi-interest Archive, December 2007
scene events not received?
Message 1 in thread
What's going wrong when I can't receive scene events to my graphics scene
items. They're visible and enabled (also tried setting the selectable flag)
but the event handling methods are just not called (I've tried overriding
and setting the ones I need to just output stuff to stdout). The events are
correctly handled from the corresponding methods in my QGraphicsView (so I
can actually pick out the ones by doing itemAtPosition(QPoint) but would be
nice to find out how to do this with event handling from the items
themselves. The items I have are simply glorified rectangles (extend
QGraphicsRectItem).
Matias
Message 2 in thread
Ok, answering here to my own question: I'd overrident the mousePressEvent()
etc methods in the graphicsview such that the superclass corresponding
method was never called... This makes the scene view items never receive
those events. Don't know if this is overall bad practice and causes other
unwanted behaviour and something I shouldn't do with widgets that override
QGraphicsView?
On Dec 4, 2007 11:14 PM, Matias Piipari <matias.piipari@xxxxxxxxx> wrote:
> What's going wrong when I can't receive scene events to my graphics scene
> items. They're visible and enabled (also tried setting the selectable flag)
> but the event handling methods are just not called (I've tried overriding
> and setting the ones I need to just output stuff to stdout). The events are
> correctly handled from the corresponding methods in my QGraphicsView (so I
> can actually pick out the ones by doing itemAtPosition(QPoint) but would be
> nice to find out how to do this with event handling from the items
> themselves. The items I have are simply glorified rectangles (extend
> QGraphicsRectItem).
>
> Matias
>
Message 3 in thread
Hi, Matias.
Matias Piipari wrote:
> Ok, answering here to my own question: I'd overrident the
> mousePressEvent() etc methods in the graphicsview such that the
> superclass corresponding method was never called... This makes the
> scene view items never receive those events. Don't know if this is
> overall bad practice and causes other unwanted behaviour and something
> I shouldn't do with widgets that override QGraphicsView?
In general: Unless you specifically aim to disable the original event
handling code, you should call the super class implementation of the
methods to ensure that all the necessary work is performed.
protected void mousePressEvent(QMouseEvent e) {
/* my event handling */
super.mousePressEvent(e);
}
Personally, I make this a rule whenever I override a virtual method and
I am only seeking to add behavior, not remove it, even if I know the
super class implementation is currently empty, as that is something
which could easily change in the future.
-- Eskil