{
double static x[4],y[4];
int static i;
if ((event
->type
() == QEvent::GraphicsSceneMouseRelease) && (Draw3Points
== true)) { QPointF img_coord_pt
= mouseEvent
->scenePos
();
x[i] = img_coord_pt.x();
y[i] = img_coord_pt.y();
i++;
if (i >= 4)
{
Draw3Points = false;
i=0;
};
painter.drawPolygon(points, 4);
}
return true;
} else {
return QObject::eventFilter(obj, event
);
}
}
void QTGraphicsShape::on_pushButton_clicked()
{
ui.graphicsView->setMouseTracking(true);
Draw3Points = true;
m_pGraphicsScene->installEventFilter(this);
}
bool QTGraphicsShape::eventFilter(QObject *obj, QEvent *event)
{
double static x[4],y[4];
int static i;
if ((event->type() == QEvent::GraphicsSceneMouseRelease) && (Draw3Points == true)) {
QGraphicsSceneMouseEvent *mouseEvent = static_cast< QGraphicsSceneMouseEvent* >( event );
QPointF img_coord_pt = mouseEvent->scenePos();
x[i] = img_coord_pt.x();
y[i] = img_coord_pt.y();
i++;
if (i >= 4)
{
Draw3Points = false;
i=0;
static const QPointF points[4] = {
QPointF(x[0], y[0]),
QPointF(x[1], y[1]),
QPointF(x[2], y[2]),
QPointF(x[3], y[3])
};
QPainter painter(this);
painter.drawPolygon(points, 4);
}
return true;
} else {
return QObject::eventFilter(obj, event);
}
}
void QTGraphicsShape::on_pushButton_clicked()
{
ui.graphicsView->setMouseTracking(true);
Draw3Points = true;
m_pGraphicsScene->installEventFilter(this);
}
To copy to clipboard, switch view to plain text mode
Bookmarks