win8789
win8789

Reputation: 63

Create an open polygon in Qt (line strips)

How can I create an open polygon, with using a QVector to initialise the polygon, in Qt?

QPolygonF will always close the Polygon and connect the last point with the first one.

Thank you for help

[Edit]

In QGraphicsScene

QVector<QPointF> test{{1,1},{100,1},{100,100}};
QPolygonF polygon(test);
addPolygon(polygon);
qDebug() << polygon.isClosed();
qDebug() << polygon.first() << polygon.last();

Output:

Upvotes: 2

Views: 1474

Answers (1)

ilotXXI
ilotXXI

Reputation: 1085

Do you mean something like this:

QVector<QPointF> test{{1,1},{100,1},{100,100}};
QPainterPath path(test.front());
for (size_t i = 1; i < test.size(); ++i)
    path.lineTo(test[i]);
scene->addPath(path);

?

QPolygonF is a polygon, not it's unfinished line. It is drawn as a closed polygon with pen-defined line (can be invisible) filled by brush (also can be invisible).

Upvotes: 4

Related Questions