[Qt-interest] Overridden wheelEvent not being called
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Mon Jan 24 10:43:38 CET 2011
On 2011-01-21 Derek Cole, Derek wrote:
> Is it possible that the way I am creating the new item, which is
> within a function, is getting deleted when the function goes out of
> scope? I have the scene declared as a global variable, but not the
> ImagePixmapItem.
I haven't looked at your code in detail, so sorry when stating the very obvious here. In general you need to allocate scene items on the heap! The scene then takes ownership when you add the items to the scene:
http://doc.qt.nokia.com/latest/qgraphicsscene.html#addItem
However I did notice that you call
http://doc.qt.nokia.com/latest/qgraphicsscene.html#addPixmap
which internally creates a QGraphicsPixmap item for you and returns a pointer to it.
But where exactly not do you expect the mouse wheel events to be received? Within that QGraphicsPixmap item, right? You either need to subclass that class and re-implement the wheel event in that subclass, and add that subclass as mentioned above (addItem()) to your scene, or you need to install an event filter on the returned QGraphicsPixmap which then handles the wheel events for that item.
In my own actual code I do the former approach and derive from QGraphicsPixmap and re-implement the wheel event - works as expected.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list