PDA

View Full Version : QPainter - fill rect with gradient



szisziszilvi
17th January 2011, 12:57
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. :(

wysota
17th January 2011, 13:38
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);