
Originally Posted by
Uwe
QWidget does not offer to "erase" something - all you can do is to redraw from scratch. This is why QwtPlotDirectPainter is useful - it at least allows to draw on top of something existing.
Uwe
Another way to achieve the effect I want,and in this way, the CPU usage is also very small,but need to write a lot of code,use the most primitive QPainter , not as concise as the qwt.The code snippet is as follows:
{
painter.drawPixmap(0,0,m_gridPixmap);//paint grid backgroup pixmap
painter.drawPixmap(0,0,m_curvePixmap);//paint curve pixmap on the top, and set QPainter::CompositionMode_Source mode when paint m_curvePixmap
painter.end();
}
void Mywidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
painter.drawPixmap(0,0,m_gridPixmap);//paint grid backgroup pixmap
painter.drawPixmap(0,0,m_curvePixmap);//paint curve pixmap on the top, and set QPainter::CompositionMode_Source mode when paint m_curvePixmap
painter.end();
}
To copy to clipboard, switch view to plain text mode
void Mywidget::updateCurvePixmap()
{
painter.begin(&m_curvePixmap);
painter.
setCompositionMode(QPainter::CompositionMode_Source);
//Calculate the current 12 refreshed area first,and fill transparent
for(int i = 0; i < 12;i++)
{
QRect rect;
//The calculation process is omitted here!!! painter.fillRect(rect,Qt::transparent);
//Plot newly added data points
QPolygonF points;
//The process of filling points is omitted!!! painter.drawPoints(points);
}
painter.end();
//At this point, the new data point is successfully partial updated on the m_curvePixmap,Partial refresh widget
QRegion region;
//save all need updated area for(int i = 0; i < 12;i++)
{
QRect rect;
//The calculation process is omitted here!!! region += rect;
}
update(region );
}
void Mywidget::updateCurvePixmap()
{
QPainter painter;
painter.begin(&m_curvePixmap);
painter.setCompositionMode(QPainter::CompositionMode_Source);
//Calculate the current 12 refreshed area first,and fill transparent
for(int i = 0; i < 12;i++)
{
QRect rect;//The calculation process is omitted here!!!
painter.fillRect(rect,Qt::transparent);
//Plot newly added data points
QPolygonF points;//The process of filling points is omitted!!!
painter.drawPoints(points);
}
painter.end();
//At this point, the new data point is successfully partial updated on the m_curvePixmap,Partial refresh widget
QRegion region;//save all need updated area
for(int i = 0; i < 12;i++)
{
QRect rect;//The calculation process is omitted here!!!
region += rect;
}
update(region );
}
To copy to clipboard, switch view to plain text mode
Refer to this example:https://doc.qt.io/qt-5/qtwidgets-pai...n-example.html,
Used this class method:QPainter::setCompositionMode.
In order to achieve the effect I want, is this the only way?
Bookmarks