最近画辅助线有刚需,画图增加绘制多线段功能。
QPolygon Inherits: QVector
mainwindow.cpp
{
connect(ui->action_polyline, SIGNAL(triggered(bool)), imageWidget, SLOT(drawPolyline()));
}
imagewidget.h
{
private:
QPolygon polygon;
}
imagewidget.cpp
void ImageWidget::drawPolyline()
{
image = imgtemp;
drawType = POLYLINE_DRAW;
setCursor(QCursor(QPixmap(":/icon/polyline.png")));
polygon.clear();
}
void ImageWidget::draw(QImage &img)
{
...
case POLYLINE_DRAW:
polygon.append(startPnt);
painter.drawPolyline(polygon);
break;
...
}
void ImageWidget::mousePressEvent(QMouseEvent *e)
{
startPnt = e->pos();
endPnt = e->pos();
switch (drawType) {
case POLYLINE_DRAW:
draw(imgtemp);
image = imgtemp;
moveImgbuf();
break;
...
}
Qt画折线