当前位置: 首页 > news >正文

网站流量图怎么做直播代运营公司

网站流量图怎么做,直播代运营公司,wordpress数据库恢复插件,个人网站的制作论文目录参考结构PicturePlay.promain.cpppictureplay.hpictureplay.cpppictureplay.ui效果源码参考 Qt图片浏览器 QT制作一个图片播放器 Qt中自适应的labelpixmap充满窗口后,无法缩小只能放大 可以显示jpg、jpeg、png、bmp。可以从电脑上拖动图到窗口并显示出来或者打开…

目录

  • 参考
    • 结构
    • PicturePlay.pro
    • main.cpp
    • pictureplay.h
    • pictureplay.cpp
    • pictureplay.ui
  • 效果
  • 源码

参考

Qt图片浏览器

QT制作一个图片播放器

Qt中自适应的label+pixmap充满窗口后,无法缩小只能放大

可以显示jpg、jpeg、png、bmp。可以从电脑上拖动图到窗口并显示出来或者打开文件选择,定时滚动图片

重载实现dragEnterEvent(拖拽)、dropEvent(拖拽放下)、resizeEvent(窗口大小改变)

结构

在这里插入图片描述

PicturePlay.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \pictureplay.cppHEADERS += \pictureplay.hFORMS += \pictureplay.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetRESOURCES += \res.qrc

main.cpp

#include "pictureplay.h"#include <QApplication>
#include<QFile>
int main(int argc, char *argv[])
{QApplication a(argc, argv);// 加载样式文件QFile file(":/style.qss");/*判断文件是否存在*/if(file.exists()){file.open(QFile::ReadOnly);// 以只读的方式打开//QString styleSheet=QLatin1String(file.readAll());// 以Latin-1编码的字符串的方式保存读出的结果QString styleSheet=QString(file.readAll());// 以默认编码的字符串的方式保存读出的结果qApp->setStyleSheet(styleSheet);// 设置全局样式file.close();// 关闭文件}PicturePlay w;w.show();return a.exec();
}

pictureplay.h

#ifndef PICTUREPLAY_H
#define PICTUREPLAY_H#include <QWidget>
#include <QFile>
#include <QDir>
#include <QTimer>
#include <QThread>
#include <QFileDialog>
QT_BEGIN_NAMESPACE
namespace Ui { class PicturePlay; }
QT_END_NAMESPACEclass PicturePlay : public QWidget
{Q_OBJECTpublic:PicturePlay(QWidget *parent = nullptr);~PicturePlay();
private slots:void myautoPhoto(); //自动播放函数void showDinamicPhoto(QString path);//动态图播放(格式为gif)void on_pathBtn_clicked();//浏览:打开目录void on_autoPhoto_clicked(bool checked);//自动播放选择void on_photoList_clicked(const QModelIndex &index);//单击播放图片void my_currentRowChanged(int Row);// // 当前项变化void on_cleanBtn_clicked();//清除private:QString Dir;//打开文件的路径QString tempDir; //照片的绝地路径QVector<QString> photoPath;//存放照片相对路径的容器QTimer *mtime; //定时器QString delayTime; //延时间隔bool autoFlag; //判断是否进入的自动播放格式int num; //照片张数// 如果文件的后缀名是jpg、jpeg、bmp或png,则接受拖放事件,否则忽略拖放事件QStringList acceptedFileTypes;void dragEnterEvent(QDragEnterEvent *event)override;//拖进事件void dropEvent(QDropEvent *event)override;// 拖进放下事件void resizeEvent(QResizeEvent *event)override;//用于在窗口大小改变时处理事件QPixmap pixmap;
private:Ui::PicturePlay *ui;
};
#endif // PICTUREPLAY_H

pictureplay.cpp

#include "pictureplay.h"
#include "ui_pictureplay.h"
#include<QDebug>
#include<QMessageBox>
#include<QMovie>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
PicturePlay::PicturePlay(QWidget *parent): QWidget(parent), ui(new Ui::PicturePlay)
{ui->setupUi(this);this->setWindowTitle("图片播放器");this->setWindowIcon(QIcon(":/ImageEye.jpg"));this->setAcceptDrops(true);//设置允许向窗口拖入图片this->setMinimumSize(QSize(400,300));// 设置最小值ui->photoShow->setAlignment(Qt::AlignCenter);  //居中显示//自适应的label+pixmap充满窗口后,无法缩小只能放大ui->photoShow->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);// Ignored忽略// 设置拉伸因子(默认缩到最小时失效:一样大小)ui->horizontalLayout_2->setStretch(1,3);//  设置水平布局控件到边框距离(左,上,右,下)ui->horizontalLayout_2->setContentsMargins(5,0,5,0);//设置窗口布局,(此时控件会随窗口缩放)this->setLayout(ui->horizontalLayout_2);ui->photoPath->setFocusPolicy(Qt::NoFocus);//无法获得焦点,自然无法输入,其他文本控件类似ui->photoPath->setPlaceholderText("绝对路径");ui->delayEdit->setPlaceholderText("秒");//不显示行向滚动条,子项文本过长自动显示...ui->photoList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);num=0; //照片张数delayTime.clear(); //延时间隔mtime = new QTimer(this);//连接自动播放槽函数connect(mtime,SIGNAL(timeout()),this,SLOT(myautoPhoto()));connect(ui->photoList,SIGNAL(currentRowChanged(int)),this,SLOT(my_currentRowChanged(int)));// 如果文件的后缀名是jpg、jpeg、bmp或png,则接受拖放事件,否则忽略拖放事件acceptedFileTypes.append("jpg");acceptedFileTypes.append("jpeg");acceptedFileTypes.append("bmp");acceptedFileTypes.append("png");acceptedFileTypes.append("gif");
}PicturePlay::~PicturePlay()
{delete ui;
}
//自动播放函数
void PicturePlay::myautoPhoto()
{tempDir.clear();tempDir=photoPath.at(num); //从容器中找到要播放的照片的相对路径ui->photoList->setCurrentRow(num);// QListWidget项跳动if(tempDir.endsWith(".gif")  || tempDir.endsWith(".Gif")){showDinamicPhoto(tempDir);num++;}else if(!(tempDir.endsWith(".gif")  || tempDir.endsWith(".Gif"))){// 内容是否自动缩放,参数true自动缩放ui->photoShow->setScaledContents(true);//显示图片的全部pixmap.load(tempDir);// 更新全局图片ui->photoShow->setPixmap(QPixmap(tempDir));//显示图片//判断自动播放的时候是否播放到了最后一张图片,如果是则停止自动播放if(num ==  (photoPath.count()-1)){//qDebug()<<num;if(ui->loopPlayback->checkState()==Qt::Checked)//循环重放{num = -1;// 下面num++,为了循环重放回到第一张图片qDebug()<<num;}else{mtime->stop();num = 0;if(autoFlag)//选中自动播放的情况{autoFlag = false;}//qDebug()<<num;ui->autoPhoto->setCheckState(Qt::Unchecked);//把自动播放按钮置于没有选择的状态}}if(autoFlag){num++;}}
}
//动态图播放(格式为gif)
void PicturePlay::showDinamicPhoto(QString path)
{QMovie *movie = new QMovie(path);  // path图片路径movie->start(); //开始播放动态图ui->photoShow->setMovie(movie); //将图片设置为为动态ui->photoShow->setScaledContents(true); //尽可能完整的播放整张动图 ,此处要设置为true
}//浏览:打开目录
void PicturePlay::on_pathBtn_clicked()
{Dir = QFileDialog::getExistingDirectory(this);//获取本文件所在的具体路径//qDebug()<<"路径:"<<Dir;ui->photoPath->setText(Dir);//显示打开的文件的具体路径QDir dir(Dir);QStringList file;QFileInfoList fileList = dir.entryInfoList(file,QDir::Files); //获取目录下的文件QString fileDir; //保存图片所在的路径//列出目录下的文件for(int i=0;i<fileList.count();i++){if(i==100)//只加载100张,防止加载过久{break;}QFileInfo info = fileList.at(i);fileDir.clear();if(info.fileName() == "." || info.fileName() == "..") //跳过这两个目录{continue;}// 检查文件的后缀名是否在接受的文件类型列表中;(获取文件的后缀名,并将其转换为小写字母)if(!acceptedFileTypes.contains(info.suffix().toLower())){continue;}fileDir+=Dir + "/";QString filename = info.fileName();fileDir+=filename;photoPath.append(fileDir);// 把图片的路径装到容器中QListWidgetItem *item = new QListWidgetItem(QIcon(fileDir),info.fileName());//建立文件缩小图标item->setToolTip(info.fileName());// tip提示item->setTextAlignment(Qt::AlignCenter);//设置item项中的文字位置ui->photoList->addItem(item);//把图片相对路径显示到窗口中}if(ui->photoList->count()==0){QListWidgetItem *item = new QListWidgetItem("无合适图片");item->setTextAlignment(Qt::AlignCenter);//设置item项中的文字位置ui->photoList->addItem(item);//把图片相对路径显示到窗口中}
}//自动播放选择
void PicturePlay::on_autoPhoto_clicked(bool checked)
{if(ui->delayEdit->text().isEmpty()){QMessageBox::warning(this,"提示","请输入需要间隔的播放时间(秒)");//把按钮重新置于没有被选中的状态;不要用setCheckable()函数[不可用],很容易出错ui->autoPhoto->setCheckState(Qt::Unchecked);return;}else if(ui->photoList->count() == 0){QMessageBox::warning(this,"警告","还没有可以播放的图片");ui->autoPhoto->setCheckState(Qt::Unchecked); //把按钮重新置于没有被选中的状态return;}else if(checked) //启动定时器{delayTime = ui->delayEdit->text();mtime->start(delayTime.toInt()*1000);//启动定时器并设置播放时间间隔autoFlag = true;// 选中自动播放// 第一次:立即显示,无需等待// 内容是否自动缩放,参数true自动缩放ui->photoShow->setScaledContents(true);//显示图片的全部pixmap.load(photoPath.at(num));// 更新全局图片ui->photoShow->setPixmap(QPixmap(photoPath.at(num)));//显示图片}else if(!checked)//停止定时器{mtime->stop();//停止定时器delayTime.clear();autoFlag = false;}
}//单击播放图片
void PicturePlay::on_photoList_clicked(const QModelIndex &index)
{qDebug()<<"单击播放图片";Q_UNUSED(index);//忽略编译器发出的警告,表明变量event未使用//如果选中了自动播放的情况下,点击列表中的内容,则停止自动播放if(autoFlag) //选中自动播放的情况{mtime->stop();//把按钮重新置于没有被选中的状态;不要用setCheckable()函数[不可用],很容易出错ui->autoPhoto->setCheckState(Qt::Unchecked);autoFlag = false;}num = ui->photoList->row(ui->photoList->currentItem()); //获取当前点击的内容的行号//在没有选中自动播放的情况下,判断当前是否点击了最后一张照片,如果是最后一张照片,在选中自动播放的情况下让它返回到第一张照片if(!autoFlag&&num == ui->photoList->count()){num = 0;}tempDir.clear();/*tempDir+=Dir+"/";QString path = ui->photoList->currentItem()->text();tempDir+=path*/;tempDir=photoPath.at(num); //从容器中找到要播放的照片的相对路径//判断是否是动态图;endsWith()字符串结尾if(tempDir.endsWith(".gif") || tempDir.endsWith(".Gif")){showDinamicPhoto(tempDir);}else{// 内容是否自动缩放,参数true自动缩放ui->photoShow->setScaledContents(true);//显示图片的全部pixmap.load(tempDir);// 更新全局图片ui->photoShow->setPixmap(QPixmap(tempDir));//显示图片}
}
// 当前项变化
void PicturePlay::my_currentRowChanged(int Row)
{qDebug()<<"当前项变化:"<<Row;
}
//拖进事件
void PicturePlay::dragEnterEvent(QDragEnterEvent *event)
{// 用于检查拖放的数据是否包含URL,并且获取拖放事件中的URL数量==1if(event->mimeData()->hasUrls()&&event->mimeData()->urls().count()==1){// 获取拖放事件中的第一个URL的本地文件路径QFileInfo file(event->mimeData()->urls().at(0).toLocalFile());// 检查文件的后缀名是否在接受的文件类型列表中;(获取文件的后缀名,并将其转换为小写字母)if(acceptedFileTypes.contains(file.suffix().toLower())){event->acceptProposedAction();//表明用户可以在窗口部件上拖放对象[接受拖放事件的操作]}}
}
// 拖进放下事件
void PicturePlay::dropEvent(QDropEvent *event)
{// 获取拖放事件中的第一个URL的本地文件路径QFileInfo file(event->mimeData()->urls().at(0).toLocalFile());//qDebug()<<"绝对路径:"<<file.absoluteFilePath();//从文件中加载图片,参数file.absoluteFilePath()表示包含文件名的绝对路径,load()返回一个bool值,表示是否加载成功if(pixmap.load(file.absoluteFilePath())){// 将图片缩放到指定大小,参数ui->label->size()表示缩放的大小,Qt::KeepAspectRatio表示保持图片的宽高比,Qt::SmoothTransformation表示使用平滑缩放算法ui->photoShow->setPixmap(pixmap.scaled(ui->photoShow->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));ui->photoPath->setText(file.absolutePath());//显示打开的文件的绝对路径,这不包括文件名。photoPath.append(file.absoluteFilePath());// 把图片的路径装到容器中QListWidgetItem *item = new QListWidgetItem(QIcon(file.absoluteFilePath()),file.fileName());//建立文件缩小图标item->setToolTip(file.fileName());// tip提示item->setTextAlignment(Qt::AlignCenter);//设置item项中的文字位置ui->photoList->addItem(item);//把图片相对路径显示到窗口中}else{// 错误消息框QMessageBox::critical(this,tr("Error"),tr("The image file count not be read"));}
}
//用于在窗口大小改变时处理事件
int i=0;
void PicturePlay::resizeEvent(QResizeEvent *event)
{Q_UNUSED(event);//忽略编译器发出的警告,表明变量event未使用qDebug()<<"窗口大小改变:"<<i++;if(!pixmap.isNull()){ui->photoShow->setPixmap(pixmap.scaled(ui->photoShow->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));}
}
// 清除
void PicturePlay::on_cleanBtn_clicked()
{mtime->stop();num = 0;if(autoFlag)//选中自动播放的情况{autoFlag = false;}pixmap.fill(Qt::transparent);//函数用于将QPixmap对象pixmap清空,参数Qt::transparent表示填充透明色,无返回值ui->autoPhoto->setCheckState(Qt::Unchecked);//把自动播放按钮置于没有选择的状态ui->loopPlayback->setCheckState(Qt::Unchecked);//把循环重放钮置于没有选择的状态photoPath.clear();ui->photoPath->clear();ui->photoShow->clear();ui->photoList->clear();
}

pictureplay.ui

在这里插入图片描述

效果

  • 启动
    在这里插入图片描述
  • 运行
    在这里插入图片描述
    在这里插入图片描述

源码

有道云:Qt图片定时滚动播放器

http://www.hkea.cn/news/711320/

相关文章:

  • 苏州乡村旅游网站建设策划书网站建设百度推广
  • 12380网站建设情况总结百度浏览器入口
  • 直播网站开发要多久排行榜前十名
  • 网站备案完才能建站吗企业建站公司
  • 网站开发外包合同西安网站优化公司
  • 2022网页设计尺寸规范和要求怎么做seo关键词优化
  • 北京大学两学一做网站十大收益最好的自媒体平台
  • 网站开发服务费企业网站建设的一般要素
  • 台州企业网站制作公司郴州网站推广
  • 如何做移动端网站邮件营销
  • 网站制作佛山crm管理系统
  • 网站综合营销方案设计网页设计教程
  • 东莞做网站制作宁波技术好的企业网站制作
  • 广州做网站公司哪家好如何注册一个网站
  • 网站备案协议书互联网营销师证书含金量
  • 广州企业网站建设报价免费推广网站大全
  • 宁波网站排名怎么提交网址让百度收录
  • 杭州 手机网站建设活动营销
  • 加网络网站建设工作室做一个企业网站大概需要多少钱
  • 张家港优化网站seo百度网盘下载
  • 烟台有没有做网站网站安全
  • 网站建设与制作设计公司惠州seo代理商
  • 东营新闻网今日头条常州网站seo
  • 东莞全网合一网站黄页引流推广网站软件免费
  • wordpress的数据库在那里百度seo如何快速排名
  • wordpress手机客服代码免费seo快速排名工具
  • web网站开发作品关键词歌词图片
  • 汕头行业网站seo培训公司
  • 网站背景图片优化关键词歌曲免费听
  • 郑州做网站哪家专业我要发布信息