Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

c++ - How to clear previously drawn polygons before rotating Qpainter?

I am trying to construct an odometer in qt.The Idea is that I draw a convex polygon using QPainter , and then I rotate the QPainter instance using the QPainter::rotate() function ,followed by a QLabel::setPixmap() to update it on the screen, however , I can see the previously drawn polygons , how can I get rid of them?I know of eraserect function , but I'm looking for a better alternative since eraserect erases the entire rectangle.Also, is there a way where I don't have to call setpixmap again and again? Here's the code:

for(int i=0;i<23;i++)
   {
     paint.rotate(8); // paint is a QPainter instance initialized with a QPixmap instance
    paint.drawConvexPolygon(pts , 3);
     ui->needle->setPixmap(pin);
}
question from:https://stackoverflow.com/questions/65829469/how-to-clear-previously-drawn-polygons-before-rotating-qpainter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need to erase anything if you do all painting in QWidget::paintEvent(). You can trigger paintEvent by calling update() when state of the widget changes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...