QPen pen(Qt::red); // Create a red pen pen.setWidth(2); // Set the width of the pen pen.setStyle(Qt::DashLine); // Set a dash line style QPainter painter(this); painter.setPen(pen); // Set the pen for the painter painter.drawLine(QPointF(0, 0), QPoint(100, 100)); // Draw a line with the pen
QPen pen(Qt::blue); // Create a blue pen pen.setWidth(1); // Set the width of the pen pen.setStyle(Qt::SolidLine); // Set a solid line style QBrush brush(Qt::yellow); // Create a yellow brush QPainter painter(this); painter.setPen(pen); // Set the pen for the painter painter.setBrush(brush); // Set the brush for the painter painter.drawRect(QRectF(0, 0, 50, 50)); // Draw a rectangle with the pen and brushBoth of these examples use the Qt library, specifically the QPainter class which is used for drawing 2D graphics.