#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); // Create a polygon with 4 points QPolygon poly({ {0, 0}, {50, 0}, {50, 50}, {0, 50} }); // Print the number of points in the polygon qDebug() << "Number of points:" << poly.size(); // Add a new point to the polygon poly.append( QPoint(25, 75) ); // Print the updated number of points qDebug() << "New number of points:" << poly.size(); return app.exec(); }
#includeThis example creates a QPolygon with 4 points and then fills it with a red color using a QPainter. The resulting image is saved to a file.int main(int argc, char *argv[]) { QApplication app(argc, argv); // Create a polygon with 4 points QPolygon poly({ {0, 0}, {50, 0}, {50, 50}, {0, 50} }); // Create a paint device and painter QImage image(100, 100, QImage::Format_RGB32); QPainter painter(&image); // Set the color and fill the polygon painter.setBrush(Qt::red); painter.drawPolygon(poly); // Save the image to a file image.save("polygon.png"); return app.exec(); }