Drawing QPolygonF to QSGGeometry
Unsolved
QML and Qt Quick
-
I'm trying to draw a polygon using QSGGeometry/QSGFlatColorMaterial. If I draw a rectangle with right corners, then everything works correctly:
QPolygonF polygon; // Rectangle with right corners polygon << QPointF(0, 0) << QPointF(230, 0) << QPointF(230, 230) << QPointF(0, 230) << QPointF(0, 0); QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), polygon.count()); QSGFlatColorMaterial *material = new QSGFlatColorMaterial(); material->setColor(QColor("red")); QSGGeometry::Point2D *vertices = geometry->vertexDataAsPoint2D(); for (int i = 0; i < polygon.count(); i++) { QPointF point = polygon.at(i); vertices[i].set(point.x(), point.y()); } QSGGeometryNode *node = new QSGGeometryNode(); node->setGeometry(geometry); node->setMaterial(material);
Correct result:
But if I try to draw a rectangle with rounded corners:// Rounded rectangle polygon << QPointF(0, 10) << QPointF(0.78585, 6.10755) << QPointF(2.92893, 2.92893) << QPointF(6.10755, 0.78585) << QPointF(10, 0) << QPointF(220, 0) << QPointF(223.892, 0.78585) << QPointF(227.071, 2.92893) << QPointF(229.214, 6.10755) << QPointF(230, 10) << QPointF(230, 220) << QPointF(229.214, 223.892) << QPointF(227.071, 227.071) << QPointF(223.892, 229.214) << QPointF(220, 230) << QPointF(10, 230) << QPointF(6.10755, 229.214) << QPointF(2.92893, 227.071) << QPointF(0.78585, 223.892) << QPointF(0, 220) << QPointF(0, 10);
Then I get this result:
I need the outline of the rectangle to be filled with color. What could be the problem and how to fix it?