关键代码是派生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展示蒙版效果的更多相关文章

  1. css遮罩蒙版效果 分栏效果

    mask遮罩蒙版效果 来看一下效果图: 这是两张原图: 遮罩层图像 注意,白色区域为透明状态   要展示的图像 使用mask之后产生的效果图   首先来解释一下遮罩.蒙版.和PS中的蒙版.Flash中 ...

  2. jQuery图片旋转展示收缩效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. CorelDRAW 实现蒙版效果的方法

    CorelDRAW能够实现很多意想不到的小效果,其中包括了位图图像软件的处理功能,蒙版效果就是其中的一项.作为矢量图形处理软件,从理论上讲它并不具备蒙板技术,然而只是我们平常没有用到而已,利用图框精确 ...

  4. 浅谈css蒙版效果

    我们进网站浏览时经常看到当鼠标悬浮在图片上或者某一个地方时,会出现一层朦胧现象覆盖着悬浮位置,简单的理解为“蒙版效果”.下面简单列举实现过程: HTML: CSS:

  5. 浅谈图片蒙版效果-webkit-mask

    会用PS的童鞋一定知道“蒙版”的概念,它可以在图片上实现一定的遮罩效果,当然这里我们不介绍ps里的蒙版,而是介绍利用CSS3的新属性-webkit-mask来实现网页中的图片遮罩效果. 大家对-web ...

  6. QT窗口渐现效果,窗口震动效果,鼠标移动窗口

    //窗口渐现效果void MainWindow::closeWindowAnimation() //关闭窗口效果 { QPropertyAnimation *animation = new QProp ...

  7. Qt实现悬浮窗效果

    当鼠标移动到头像控件时,显示悬浮窗,当鼠标离开时,悬浮窗隐藏.   1.控件选择 悬浮窗可以从QDialog派生,并将窗口的属性设置为无边框 this->setWindowFlags(this- ...

  8. Qt实现半透明遮罩效果

    本文索引: 需求 原理 实现遮罩控件 遮罩的使用 需求 我们在显示一些模态对话框的时候,往往需要将对话框的背景颜色调暗以达到突出当前对话框的效果,例如: 对话框的父窗口除了标题栏以外的部分都变暗了,在 ...

  9. 后端数据中含有html标签和css样式,前端如何转译展示样式效果。

    后端含有html标签和css样式的数据: domain="<span style='color:red'>www.baidu.com</span>" (vu ...

随机推荐

  1. ADB三个进阶使用

    adb通过Wi-Fi连接手机 背景知识 Android系统底层运行着一个服务(adbd),也就是在手机系统内部,用于响应.管理大家在电脑端的adb命令连接,这个服务在启动时候会根据手机的配置监听USB ...

  2. 【python】字典/dictionary操作

    字典(dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号:分割,每个键值对之间用逗号,分割,整个字典包括在花括号 {} 中 ...

  3. 3hibernate核心对象关系映射 xxx.hbm.xml

    Hibernate的核心就是对象关系映射: 加载映射文件的两种方式: 第一种:<mapping resource="com/bie/lesson02/crud/po/employee. ...

  4. Android中两个Activity之间简单通信

    在Android中,一个界面被称为一个activity,在两个界面之间通信,采用的是使用一个中间传话者(即Intent类)的模式,而不是直接通信. 下面演示如何实现两个activity之间的通信. 信 ...

  5. MySQL面试题36道

    MySQL数据库是在免费的数据库中最受欢迎的一款,尤其是在一些小型项目以及项目资金有限的情况下,选择MySQL来作为数据存储的工具,那些不差钱并且数据吞吐量非常大的互联网公司一般都是会用付费的Orac ...

  6. hadoop集群为分布式搭建

    1.准备Linux环境设置虚拟机网络    1.0点击VMware快捷方式,右键打开文件所在位置 -> 双击vmnetcfg.exe -> VMnet1 host-only ->修改 ...

  7. String真的是不可变的吗?

    你可能问一个人String是可变的吗?想必他们都会一口同生的说String是不可变的,因为String是final修饰的,而且它底层的是final修饰的char[]数组. 可以看到String源码: ...

  8. sqlserver 镜像 断开连接 正在恢复+主机服务器关机用备用镜像

    如果主机坏了断开连接就用备机的镜像数据库 --主备互换,备机sql命令 USE master;   ALTER DATABASE test SET PARTNER FORCE_SERVICE_ALLO ...

  9. Java多线程学习笔记之二缓存

    1.高速缓存 由来:处理器处理能力原因大于主内存(DRAM)访问速率,为了弥补这个差距,引入了高速缓存. 高速缓存是一种存取速率远比主内存大而容量远比主内存小的存储部件,每一个处理器都有其高速缓存.在 ...

  10. 让sublime text3支持Vue语法高亮显示[转]

    1.准备语法高亮插件vue-syntax-highlight. 下载地址:https://github.com/vuejs/vue-syntax-highlight 下载页面并下载: 解开压缩包vue ...