void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(this->rect(), QColor(0, 0, 255, 80)); //QColor最后一个参数80代表背景的透明度
}
void QZXingWidget::paintEvent(QPaintEvent *event)
{
QPixmap covert_pixmap(":/Images/background");
QPixmap pixmap(covert_pixmap.width(), covert_pixmap.height());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QPoint start_point(0, 0);
QPoint end_point(0, pixmap.height());
//QLinearGradient进行渐变色设置
QLinearGradient linear_gradient(start_point, end_point);
linear_gradient.setColorAt(0, QColor(255, 255, 255, 100));
linear_gradient.setColorAt(0.5, QColor(255, 255, 255, 150));
linear_gradient.setColorAt(1, QColor(255, 255, 255, 255));
painter.fillRect(this->rect(), QBrush(linear_gradient));
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawPixmap(0, 0, covert_pixmap);
painter.end();
QPainter painter2(this);
painter2.drawPixmap(0, 0, pixmap);
}