Hello,
I defined a new type polygon. Some functions from polygon.cpp is below:
My QML file is here:Code:Polygon::Polygon(QDeclarativeItem *parent) : QDeclarativeItem(parent) { // need to disable this flag to draw inside a QDeclarativeItem setFlag(QDeclarativeItem::ItemHasNoContents, false); setFlags(ItemIsSelectable|ItemIsMovable|ItemIsFocusable); setAcceptDrops(true); setFlag(ItemSendsGeometryChanges); setCacheMode(DeviceCoordinateCache); setZValue(-1); } void Polygon::dragEnterEvent(QGraphicsSceneDragDropEvent *event){ event->acceptProposedAction(); qDebug("drag"); update(); QDeclarativeItem::dragEnterEvent(event); } void Polygon::focusInEvent ( QFocusEvent * event ){ cout<<"focusin"<<endl; update(); QDeclarativeItem::focusInEvent(event); } QRectF Polygon::boundingRect() const{ QVector<QPointF> vPnt=listToVector(m_vertices); return QPolygonF(vPnt).boundingRect(); } QPainterPath Polygon::shape () const { QPainterPath path; QVector<QPointF> vPnt=listToVector(m_vertices); path.addPolygon(QPolygonF(vPnt)); return path; } void Polygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { QPen pen(m_color, 2); painter->setPen(pen); painter->setRenderHints(QPainter::Antialiasing, true); QVector<QPointF> vPnt=listToVector(m_vertices); painter->setBrush(QBrush(m_color,Qt::SolidPattern)); painter-> drawPolygon(QPolygonF(vPnt),Qt::OddEvenFill); }
I override paint, focusInEvent, dragEnterEvent, shape, boundingRectangle functions as you can see above, but only paint works as expected. I set flags in constructor too.Code:import MyTypes 1.0 import QtQuick 1.0 import Qt 4.7 Item { id:container width: 300; height: 200 Polygon { id: aPolygon anchors.centerIn: parent width: 100; height: 100 name: "A simple polygon" color: "blue" vertices:[ Point{x:20.0; y:40.0}, Point{x:40.0; y:40.0}, Point{x:40.0; y:20.0}, Point{x:20.0; y:20.0} ] } Text { anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } text: aPolygon.name } }
When i run the application, I can see polygons those i declared in the QML file, but how to be notified when the polygon is focused in or dragged into it? I can not see cout result on console. What to do in QML side or C++ side?
Thanks for any idea.



