QPen myPen(Qt::red); //create a pen with a red color myPen.setColor(Qt::blue); //set the color of the pen to blue
QPen myPen; myPen.setColor(QColor("#00FF00")); //set the color of the pen to greenIn this example, we create a pen without specifying a color and then set the color to green using the `setColor()` method. The color is specified using a hexadecimal value. These examples use the Qt library in C++.