Normally what we will do to fill the color in widget with paintEvent is by using setPen & setBrush, as shown below.
{
p.
setPen(QPen(Qt
::black,
1, Qt
::SolidLine, Qt
::RoundCap));
p.
setBrush(QBrush(Qt
::black, Qt
::SolidPattern));
p.drawEllipse(0, 0, width() - 1, height() - 1);
p.end();
}
void paintEvent(QPaintEvent *event)
{
QPainter p(this);
p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap));
p.setBrush(QBrush(Qt::black, Qt::SolidPattern));
p.drawEllipse(0, 0, width() - 1, height() - 1);
p.end();
QLabel::paintEvent(event);
}
To copy to clipboard, switch view to plain text mode
Here in the above shown example I am filling circle with black color.
But my problem is I have to fill the circle with random colors taken from some other functionality. I cannot pass that color into this paintEvent function. So I have to do some other things which fills color for the circle outside paintEvent functionality.
So how to fill color for the circle ?
Bookmarks