QPainter - fill rect with gradient
Hi,
I'm using QPainter for painting rectangles.
This works:
painter->fillRect(myQRect,Qt::red);
But how can I define a gradient filling, like:
painter->fillRect(myQRect,Qt::LinearGradientPattern);
?
I tryed to google it, but no simple examples found. :(
Re: QPainter - fill rect with gradient
Code:
QLinearGradient gradient
(myQRect.
topLeft(), myQRect.
bottomRight();
// diagonal gradient from top-left to bottom-right gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::red);
painter->fillRect(myQRect, gradient);