QPen greenPen(Qt::green); QPainter painter(this); painter.setPen(greenPen); painter.drawRect(10, 10, 50, 50);
QColor color = QColor::fromRgb(255, 0, 0); // create QColor object with RGB values QString cssString = QString("color: %1;").arg(color.name()); // create CSS formatted string QPen customPen(Qt::PenStyle::SolidLine); customPen.setColor(color); // Set color using the CSS formatted string painter.setPen(customPen); painter.drawEllipse(100, 100, 50, 50);These examples use the Qt GUI C++ library.