[Qt-qml] QDeclarativeItem subclasses and mouse events

Jan Ekholm jan.ekholm at smultron.net
Mon Aug 2 22:13:52 CEST 2010


On Monday 02 August 2010 22:22:25 alexis.menard at nokia.com wrote:
> Hello,
> 
> QDeclarativeItemPrivate constructor does this :
> 
> QGraphicsItemPrivate::acceptedMouseButtons = 0;
> 
> which means that no mousePress/mouseMove/mouseRelease will be delivered.
> 
> You need to call setAcceptedMouseButtons in your C++ item with the buttons
> you want.

...

> I think either we should document that the default values are different
> than QGraphicsItem or we should bind Item{} to something else, otherwise
> we will get lot of mails/bug reports like this, just because the default
> values of QDeclarativeItem are different than the one in QGraphicsItem.

Ok, I read the docs for QGraphicsItem and saw this property mentioned. I was 
about to test setting it, but as the docs says:

"Mouse press events are only delivered to items that accept the mouse button 
that is pressed. By default, an item accepts all mouse buttons, but you can 
change this by calling setAcceptedMouseButtons()."

I didn't test it. However, adding in my constructor:

    setAcceptedMouseButtons( Qt::LeftButton );

makes no difference, I still see no events. Makes me suspect something else. 
The C++ item itself has been used extensively as a plain QGraphicsItem before 
in a QGraphicsView based system, and should be just fine. I more or less only 
changed it to subclass QDeclarativeItem.

I need to debug deeper, it seems.

-- 

 He says gods like to see an atheist around. Gives them something to aim at.
                                            -- Terry Pratchett, Small Gods



More information about the Qt-qml mailing list