关于Qt 中paintEvent cpu占用率高的问题,救命啊!!!
void BaseView::paintEvent( QPaintEvent *pE )
{
if (bgMask==NULL)
{
if (NULL!=bg)
{
QPainter painter(this);
painter.drawPixmap(0,0,this->width(),this->height(),*bg);
}
int arcR = 2;
if (0==m_intRectCorner)
{
QPixmap bMask(this->width(),this->height());
QPainter p(&bMask);
p.fillRect(0,0,this->width(),this->height(), Qt::white);
if (bg)
{
p.drawPixmap(0,0,this->width(),this->height(),bg->mask());
}
this->setMask(bMask);
}
//画圆角
else if(1==m_intRectCorner)
{
QBitmap bmp(this->size());
bmp.fill();
QPainter p2(&bmp);
p2.setRenderHint(QPainter::Antialiasing);
p2.setBrush(QBrush(Qt::red));
p2.drawRoundRect(bmp.rect(), arcR, arcR); //四个角都是圆弧
setMask(bmp);
}
else if(2==m_intRectCorner)
{
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setRenderHint(QPainter::Antialiasing);
QRect rect = this->rect();
QPainterPath path;
//逆时针
path.moveTo(arcR, 0);
path.arcTo(0, 0, arcR * 2, arcR * 2, 90.0f, 90.0f);
path.lineTo(0, rect.height());
path.lineTo(rect.width(), rect.height());
path.lineTo(rect.width(), arcR);
path.arcTo(rect.width() - arcR * 2, 0, arcR * 2, arcR * 2, 0.0f, 90.0f);
path.lineTo(arcR, 0);
p.drawPath(path);
p.fillPath(path, QBrush(Qt::red)); //arm和windows平台没有这行代码将显示一个透明的空空的框
setMask(bmp);
}
}
else
{
this->setMask(*bgMask);
}
}