Solved Diagram Scene Example ::paint and ::setPolygon
-
as the example Diagram Scene Example:
diagramitem.cppsetPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
item can select, move;
but when i change it a little:
to://setPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
QRectF DiagramItem::boundingRect() const { qreal penWidth = 1; switch (myDiagramType) { case StartEnd: return QRectF(0 - penWidth / 2,0 - penWidth / 2, 200 + penWidth, 200 + penWidth); break; case Conditional: return QRectF(-100 - penWidth / 2, -100 - penWidth / 2, 200 + penWidth, 200 + penWidth); case Step: return QRectF(-100 - penWidth / 2, -100 - penWidth / 2, 200 + penWidth, 200 + penWidth); case Io: return QRectF(-120 - penWidth / 2, -80 - penWidth / 2, 240 + penWidth, 160 + penWidth); } } void DiagramItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { painter->drawPolygon(myPolygon ); }
item can show but can be selected and moved, Arrow can not work also;
-
-
Reimplement mouseMoveEvent and mousePressEvent; set breakPiont . finded that it is not executed.
-
This post is deleted! -
ha, diagramitem Inherit QGraphicsPolygonItem , change it to inherit QGraphicsItem.