[Qt-qml] RE : QDeclarativeItem subclasses and mouse events

alexis.menard at nokia.com alexis.menard at nokia.com
Mon Aug 2 21:22:25 CEST 2010


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.

All default options in QDeclarativeItem are a bit strange as a base class to derive from in the C++ world.

QGraphicsItem::ItemHasNoContents for example will cause painting/update issues.

ItemNegativeZStacksBehindParent will trigger unexpected results.

I do understand the usage of QDeclarativeItem which represent the Item{} element.
Semantically Item{} does nothing BUT in the other hand we recommend to use QDeclarativeItem for adding custom C++ items in QML. 
In the later case the default options of QDeclarativeItem are a bit incorrect/weird. 

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.

Br.
________________________________________
De : qt-qml-bounces at trolltech.com [qt-qml-bounces at trolltech.com] de la part de ext Jan Ekholm [jan.ekholm at smultron.net]
Date d'envoi : lundi 2 août 2010 20:55
À : qt-qml at trolltech.com
Objet : [Qt-qml] QDeclarativeItem subclasses and mouse events

Hi,

I was recommended to make a C++ QDeclarativeItem subclass for my game map
tiles to get better performance. This worked well and the class was easy to
implement, register and get to work. However, I can't seem to get mouse
press/release events to work, whatever I do the events aren't relayed to my
items. The methods I try are:

    virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
    virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);

I guess I can make a MouseArea per item as I had before with my pure QML
solution, but it's not ideal. The items are not rectangles in shape and it's
not possible to have custom shapes for MouseArea.

I see that the shape() method is called for the correct C++ item, so
apparently something checks wether the mouse was pressed inside the C++ item,
but I never get any event.

Probably there's something trivial I'm missing here? I've looked through all
the demos and examples, but none of the C++ items are interactive that I can
see.

Any hints as to where my failure to grok stuff would be?

Kind regards,
    Jan Ekholm

--
        Five exclamation marks, the sure sign of an insane mind.
                                              -- Terry Pratchett, Reaper Man
_______________________________________________
Qt-qml mailing list
Qt-qml at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml




More information about the Qt-qml mailing list