首页 技术 正文
技术 2022年11月12日
0 收藏 913 点赞 4,598 浏览 3198 个字

关键代码是派生QOpenGLWidget,覆写paintEvent函数

QPainter p;
p.begin(this);
p.drawImage(QPoint(, ), m_Img); QLinearGradient grad(, , rect().width(), rect().height());
{
QGradientStops gs;
gs << QGradientStop(0.0, QColor(,,,))
<< QGradientStop(0.5, QColor(,,,))
<< QGradientStop(1.0, QColor(,,,));
grad.setStops(gs);
} //定义顶部蒙版高度
int m_topHeight = ;
//定义双侧蒙版宽度
int m_sideWidth = ;
//定义底部蒙版高度
int m_bottomHeight = ;
//线条长度
int iLineLen = ; //底部文字框的宽高
int iTxtHeight = ;
int iTxtWidth = ; //填充周围蒙版
//顶部
p.fillRect(, , rect().width(), m_topHeight, grad);
//底部
p.fillRect(, rect().height() - m_bottomHeight, rect().width(), m_bottomHeight, grad); //左侧
p.fillRect(, m_topHeight, m_sideWidth, rect().height() - m_topHeight - m_bottomHeight, grad); //右侧
p.fillRect(rect().width() - m_sideWidth, m_topHeight, m_sideWidth, rect().height() - m_topHeight - m_bottomHeight, grad); QPen pen;
pen.setStyle(Qt::DashDotLine);
pen.setWidth(); if(m_status == )
{
pen.setBrush(Qt::green);
}
else if(m_status == )
{
pen.setBrush(Qt::yellow);
}
else if(m_status == )
{
pen.setBrush(Qt::red);
} pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin); p.setPen(pen);
//绘制中间高亮区域矩形
//矩形宽高
int iWith =rect().width()-m_sideWidth*;
int iHeight = rect().height() -m_topHeight - m_bottomHeight; p.drawRect(m_sideWidth, m_topHeight, iWith,iHeight); QPen pen2;
pen2.setWidth(); if(m_status == )
{
pen2.setBrush(Qt::green);
}
else if(m_status == )
{
pen2.setBrush(Qt::yellow);
}
else if(m_status == )
{
pen2.setBrush(Qt::red);
} p.setPen(pen2);
//画四角的线条 //左上横线
p.drawLine(m_sideWidth,m_topHeight,m_sideWidth +iLineLen, m_topHeight);
//左上竖线
p.drawLine(m_sideWidth,m_topHeight+iLineLen,m_sideWidth,m_topHeight); //右上横线
p.drawLine(rect().width() - m_sideWidth - iLineLen,m_topHeight, rect().width() - m_sideWidth,m_topHeight); //右上竖线
p.drawLine(rect().width() - m_sideWidth,m_topHeight, rect().width() - m_sideWidth, m_topHeight + iLineLen); //右下竖线
p.drawLine(rect().width() - m_sideWidth,rect().height()-m_bottomHeight,rect().width() - m_sideWidth,rect().height()-m_bottomHeight - iLineLen);
//右下横线
p.drawLine(rect().width() - m_sideWidth,rect().height()-m_bottomHeight, rect().width() - m_sideWidth - iLineLen,rect().height()-m_bottomHeight); //左下横线
p.drawLine(m_sideWidth,rect().height()-m_bottomHeight,m_sideWidth+iLineLen, rect().height()-m_bottomHeight);
//左下竖线
p.drawLine(m_sideWidth,rect().height()-m_bottomHeight, m_sideWidth,rect().height()-m_bottomHeight -iLineLen); //绘制底部提示消息
QString strMsg = "";
if(m_status == )
{
strMsg=QStringLiteral("请通行");
}
else if(m_status == )
{
strMsg=QStringLiteral("请刷脸");
}
else if(m_status == )
{
strMsg=QStringLiteral("请对准红框");
}
p.setPen(pen);
p.drawRect(rect().width()/ - iTxtWidth/, rect().height()-m_bottomHeight + (m_bottomHeight/-iTxtHeight/), iTxtWidth, iTxtHeight ); QRect txtRect;
txtRect.setX(rect().width()/ - iTxtWidth/);
txtRect.setY(rect().height()-m_bottomHeight + (m_bottomHeight/-iTxtHeight/));
txtRect.setWidth(iTxtWidth);
txtRect.setHeight(iTxtHeight); p.setPen(pen2); QFont font;
font.setFamily("Microsoft YaHei");
// 大小
font.setPointSize();
// 使用字体
p.setFont(font); p.drawText(txtRect, Qt::AlignCenter , strMsg); p.end();

使用QMoive播放Gif的代码

 m_movie =new QMovie("F:/TestProject/QMoveTest/timg.gif");
m_timer =new QTimer(this);
 ui->lblMove->setVisible(true);        ui->lblMove->setMovie(m_movie);        m_movie->start();        //m_timer->start(3000);
QTimer::singleShot(, this, SLOT(StopMovie()));
void MainWindow::StopMovie()
{
m_movie->stop();
ui->lblMove->setVisible(false);
}

最终效果:

【Qt】QOpenGLWidget展示蒙版效果

【Qt】QOpenGLWidget展示蒙版效果+

【Qt】QOpenGLWidget展示蒙版效果

【Qt】QOpenGLWidget展示蒙版效果

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902