实现扫描的动画是一个label加定时器
label = new QLabel(this);
label->setGeometry((width() - VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2,VIEWFINDER_WIDTH,GRADUAL_WIDTH);
QImage mainimg=QImage(2*VIEWFINDER_WIDTH,GRADUAL_WIDTH,QImage::Format_ARGB32);
QPainter painter(&mainimg);
painter.setRenderHint(QPainter::Antialiasing, true);
// QRadialGradient radialGradient(mainimg.width()/2,mainimg.height()/2,100,mainimg.width()/2,mainimg.height()/2);
// radialGradient.setColorAt(0,QColor(105, 164, 53,TRANSPARENCY));
// radialGradient.setColorAt(1,QColor(200, 228, 173,TRANSPARENCY));
// painter.setBrush(radialGradient);
painter.setPen(QPen(QColor(105, 164, 53), 1));
painter.setBrush(QBrush(QColor(105, 164, 53)));
painter.drawEllipse(0,0,label->width(),5);
QPixmap pix = QPixmap::fromImage(mainimg);
label->setPixmap(pix);
整个界面是QPaintEvent绘制
Q_UNUSED(event);
QPainter painter(this);
painter.setPen(QPen(QColor(127, 194, 65), 6));
//左上
painter.drawLine(QPointF((width() - VIEWFINDER_WIDTH)/2,(height() - VIEWFINDER_HEIGHT)/2),
QPointF((width() - VIEWFINDER_WIDTH)/2 + 5,(height() - VIEWFINDER_HEIGHT)/2));
painter.drawLine(QPointF((width() - VIEWFINDER_WIDTH)/2,(height() - VIEWFINDER_HEIGHT)/2),
QPointF((width() - VIEWFINDER_WIDTH)/2 ,(height() - VIEWFINDER_HEIGHT)/2 + 5));
//右上
painter.drawLine(QPointF((width()+VIEWFINDER_WIDTH)/2,(height() - VIEWFINDER_HEIGHT)/2),
QPointF((width()+VIEWFINDER_WIDTH)/2 - 5,(height() - VIEWFINDER_HEIGHT)/2));
painter.drawLine(QPointF((width()+VIEWFINDER_WIDTH)/2,(height() - VIEWFINDER_HEIGHT)/2),
QPointF((width()+VIEWFINDER_WIDTH)/2,(height() - VIEWFINDER_HEIGHT)/2 + 5));
//左下
painter.drawLine(QPointF((width() - VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2),
QPointF((width() - VIEWFINDER_WIDTH)/2 + 5,(height() + VIEWFINDER_HEIGHT)/2));
painter.drawLine(QPointF((width() - VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2),
QPointF((width() - VIEWFINDER_WIDTH)/2 ,(height() + VIEWFINDER_HEIGHT)/2 - 5));
//右下
painter.drawLine(QPointF((width()+VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2),
QPointF((width()+VIEWFINDER_WIDTH)/2 - 5,(height() + VIEWFINDER_HEIGHT)/2));
painter.drawLine(QPointF((width()+VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2),
QPointF((width()+VIEWFINDER_WIDTH)/2,(height() + VIEWFINDER_HEIGHT)/2 - 5));
//画周边阴影
painter.setCompositionMode( QPainter::CompositionMode_Darken );
QColor darkenColor(0, 0, 0, 100);
painter.fillRect( 5, 5, width(), (height() - VIEWFINDER_HEIGHT)/2 - 5, darkenColor );
painter.fillRect( 5, (height() - VIEWFINDER_HEIGHT)/2, (width() - VIEWFINDER_WIDTH)/2 - 5, + VIEWFINDER_HEIGHT, darkenColor );
painter.fillRect( (width()+VIEWFINDER_WIDTH)/2, (height() - VIEWFINDER_HEIGHT)/2, (width() - VIEWFINDER_WIDTH)/2 , + VIEWFINDER_HEIGHT, darkenColor);
painter.fillRect( 5, (height() + VIEWFINDER_HEIGHT)/2, width() , (height() + VIEWFINDER_HEIGHT)/2, darkenColor);
效果图:
完整代码:https://download.csdn.net/download/yu_20501253/10922665