#include#include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap pixmap(300, 200); pixmap.fill(Qt::white); QPainter painter(&pixmap); QPen pen(Qt::red); pen.setWidth(2); painter.setPen(pen); painter.drawLine(QPointF(50, 50), QPointF(250, 150)); pixmap.save("line.png"); return a.exec(); }
#includeThis example creates a new QPixmap object and sets it to white. Then, it creates a QPainter object and sets the pen color to blue with a width of 4 pixels. It draws a rounded rectangle using the specified pen. Finally, it saves the pixmap as a PNG image. Library: Qt C++ library.#include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap pixmap(300, 200); pixmap.fill(Qt::white); QPainter painter(&pixmap); QPen pen(Qt::blue); pen.setWidth(4); painter.setPen(pen); QRectF rect(50, 50, 200, 100); painter.drawRoundRect(rect); pixmap.save("round_rect.png"); return a.exec(); }