I created a basic QML application that uses QQuickView to create a view and has custom QQuickItems. I want to handle mouse events on one of these QQuickItem, overriding the mousepressevent (QEvent *) method. However, when I launch the application and click on QQuickItem, the call to the mousepressevent (QEvent *) method fails .
The QQuickItem header file looks like this:
#include <QQuickItem> #include <QSGGeometry> #include <QSGFlatColorMaterial> class TriangularGeometry: public QQuickItem { Q_OBJECT public: TriangularGeometry(QQuickItem* parent = 0); QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*); void mousePressEvent(QMouseEvent *event); private: QSGGeometry m_geometry; QSGFlatColorMaterial m_material; QColor m_color; };
Note. I am using a script to render QuickItem.
This is a fragment of a cpp file:
void TriangularGeometry::mousePressEvent(QMouseEvent *event) { m_color = Qt::black; update();
I can handle mouse events from the application, but according to my requirements, I need to handle it by overriding the mousePressEvent method (QMouseEvent * event).
Sarin source share