I have elipses on QWidget that are drawn using QPainter, is there a way to delete a certain ellipse (at a certain coordinate)?
Thanks
I have elipses on QWidget that are drawn using QPainter, is there a way to delete a certain ellipse (at a certain coordinate)?
Thanks
Don't paint it the next time.
On each paint event, an implementation of paintEvent() draws "from scratch", either the whole widget, or the rect/region specified in QPaintEvent. So each paintEvent starts on an empty canvas, not on the contents from the previous paint. Thus, if you want to erase something, you must trigger a repaint via update(), and then just omit the elements you don't want to have painted.
void Speedometer::setSpeedLabelEnabled( bool enabled ) {
if ( m_speedLabelEnabled == enabled )
return;
m_speedLabelEnabled = enabled;
update(); // trigger repaint
}
void Speedometer::paintEvent( QPaintEvent* ) {
QPainter p( this );
if ( m_speedLabelEnabled ) {
p.drawEllipse( ... );
p.drawText( ..., m_currentSpeed, ... );
}
}
As Vinod Paul says: QGraphicsView might be a good option, in case you have to manage many such elements.