Reputation: 63
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
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