'QPainter doesn't change color
I'm learning Qt. I'm failing to realize the exercise of chapter 11 of Qt tutorial, which states "Change the color of the cannon when a shot is in the air." I chose to implement the change in paintCannon function (below). What's wrong with my code below?
void CannonField::paintCannon(QPainter &painter)
{
painter.setPen(Qt::NoPen);
if (autoShootTimer->isActive()){
std::cout << "in paintCannon yellow; " << std::endl;
// This gets called everytime `paintEvent` occurs.
// Please see the code in the web page (http://doc.trolltech.com/4.3/tutorial-t11-cannonfield-cpp.html) for this part.
painter.setBrush(Qt::yellow);
}else{
std::cout << "in paintCannon blue; " << std::endl;
painter.setBrush(Qt::blue);
}
painter.save();
painter.translate(0, height());
painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16);
painter.rotate(-currentAngle);
painter.drawRect(barrelRect);
painter.restore();
}
Since I first suspected Qpainter's save and restore might have been doing something wrong, I commented them out which ended up re-painting nothing.
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
