In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
这篇文章主要介绍了Qt怎样实现通用视频控件,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
一、前言
在之前做的视频监控系统中,根据不同的用户需要,做了好多种视频监控内核,有ffmpeg内核的,有vlc内核的,有mpv内核的,还有海康sdk内核的,为了做成通用的功能,不同内核很方便的切换,比如pro直接改一个DEFINE的变量名,所以需要将各种内核的使用方法做成一样的接口,这样看起来就很整齐,所以后面特意提炼了一个通用的视频控件,该控件没有具体的视频播放控制功能,需要根据不同的内核去调用具体的方法实现,后面还需要增加大华sdk或者其他第三方厂家的协议的时候,直接套用这个通用视频控件即可。
通用视频控件功能:
可设置边框大小
可设置边框颜色
可设置两路OSD标签
可设置是否绘制OSD标签
可设置标签文本或图片
可设置OSD位置 左上角+左下角+右上角+右下角
可设置OSD风格 文本+日期+时间+日期时间+图片
自定义半透明悬浮窗体,一排按钮
悬浮按钮可自定义设置,包括背景颜色+按下颜色
发送信号通知单击了哪个悬浮按钮
能够识别拖进来的文件,通知url
提供open close pause等接口
二、代码思路//设置悬浮条//顶部工具栏,默认隐藏,鼠标移入显示移除隐藏flowPanel = new QWidget(this);flowPanel->setObjectName("flowPanel");flowPanel->setVisible(false);//用布局顶住,左侧弹簧QHBoxLayout *layout = new QHBoxLayout;layout->setSpacing(2);layout->setMargin(0);layout->addStretch();flowPanel->setLayout(layout);//按钮集合名称,如果需要新增按钮则在这里增加即可QList btns;btns width() - (borderWidth * 2), height);}void VideoWidget::enterEvent(QEvent *){ //这里还可以增加一个判断,是否获取了焦点的才需要显示 //if (this->hasFocus()) {} if (flowEnable) { flowPanel->setVisible(true); }}void VideoWidget::leaveEvent(QEvent *){ if (flowEnable) { flowPanel->setVisible(false); }}//支持拖曳识别void VideoWidget::dropEvent(QDropEvent *event){ //拖放完毕鼠标松开的时候执行 //判断拖放进来的类型,取出文件,进行播放 if(event->mimeData()->hasUrls()) { QString url = event->mimeData()->urls().first().toLocalFile(); this->close(); this->setUrl(url); this->open(); emit fileDrag(url); } else if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) { QTreeWidget *treeWidget = (QTreeWidget *)event->source(); if (treeWidget != 0) { QString url = treeWidget->currentItem()->data(0, Qt::UserRole).toString(); this->close(); this->setUrl(url); this->open(); emit fileDrag(url); } }}void VideoWidget::dragEnterEvent(QDragEnterEvent *event){ //拖曳进来的时候先判断下类型,非法类型则不处理 if(event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) { event->setDropAction(Qt::CopyAction); event->accept(); } else if(event->mimeData()->hasFormat("text/uri-list")) { event->setDropAction(Qt::LinkAction); event->accept(); } else { event->ignore(); }}三、效果图
感谢你能够认真阅读完这篇文章,希望小编分享的"Qt怎样实现通用视频控件"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.