云起工作室 15711107967
无边框拖拽,伸缩

1、设置无边框 this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowMinMaxButtonsHint); //当多个按钮绑定同一个方法时,获取被点击的按钮对象QPushButton* btn = qobject_cast<QPushButton*>(sender());this->setAttribute(Qt::WA_TranslucentBackground,true);设置窗体透明this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);//设置无边框setAttribute(Qt::WA_StyledBackground); //禁止父窗口影响子窗口样式,放在子窗口里 2、无边窗口拖拽移动 在哪个组件,在哪个组件上拖动窗口,其他组件不起作用#include <qt_window.h>#pragma comment(lib,"user32.lib")void CTitleBar::mousePressEvent(QMouseEvent* event){ if(ReleaseCapture()){ QWidget* pWindow = this->window(); if(pWindow->isTopLevel()){ SendMessage(HWND(pWindow->winId()),WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0); } } event->ignore();}3、自定义窗口伸缩方法nativeEvent#include<qt_windows.h>#include<qt_windowsx.h>#include<windows.h>#include<windowsx.h>int m_nBorderWidth = 5;bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *result){ MSG* param = static_cast<MSG*>(message); switch(param->message) { case WM_NCHITTEST: { int nX = GET_X_LPARAM(param->lParam) - this ->geometry().x(); int nY = GET_Y_LPARAM(param->lParam) - this ->geometry().y(); //兼容拖拽 if( (nX>m_nBorderWidth) && (nX<this->width()-m_nBorderWidth) && (nY>m_nBorderWidth) && (nY<this->height()-m_nBorderWidth) ){ if(childAt(nX,nY) !=nullptr){ return QWidget::nativeEvent(eventType,message,result); } } if( (nX>0) && (nX<m_nBorderWidth) ){ *result = HTLEFT; } if( (nY>0) && (nY<m_nBorderWidth) ){ *result = HTTOP; } if( (nX>this->width() - m_nBorderWidth) && (nX<this->width()) ){ *result = HTRIGHT; } if( (nY>this->height()-m_nBorderWidth) && (nY<this->height()) ){ *result = HTBOTTOM; } if( (nX>0) && (nX<m_nBorderWidth) && (nY>0) && (nY < m_nBorderWidth) ){ *result = HTTOPLEFT; } if( (nX>this->width()-m_nBorderWidth) && (nX<this->width()) && (nY>0) && (nY<m_nBorderWidth) ){ *result = HTTOPRIGHT; } if( (nX>this->width() - m_nBorderWidth) && (nX<this->width()) && (nY>this->height() - m_nBorderWidth) && (nY<this->height()) ){ *result = HTBOTTOMRIGHT; } if( (nX>0) && (nX<m_nBorderWidth) && (nY > this->height() - m_nBorderWidth) && (nY<this->height()) ){ *result = HTBOTTOMLEFT; } return true; } } return false;}

libvlc

下载地址:Index of /pub/videolan/vlc/配置:(38条消息) LibVLC —— Qt下的配置(附所有出现的问题解决)_信必诺的博客-CSDN博客_qt配置libvlc1、准备    (1)默认已经安装好Qt。    (2)在上述vlc官网下载vlc一般下载.7z文件,文件中包含有sdk。2、打开vlc文件,分别将sdk、plugins拷出。在拷出的目录下创建bin文件夹,并将libvlccore.dll、libvlc.dll拷贝进去。 在工程根目录下创建vlc 目录,将sdk目录下的内容和plugins目录下的内容复制到vlc下,并在vlc下创建bin 文件夹并将libvlccore.dll、libvlc.dll拷贝进去。3、创建Qt项目。  (1)在pro文件下加入头文件、库的引用。 ############################## VLC INCLUDEPATH += vlc/include LIBS += vlc/lib/libvlc.lib //可以用绝对路径 LIBS += vlc/lib/libvlccore.lib //可以用绝对路径 ##############################   (2)在Qt中加入vlc头文件,并打开改文件加入内容 #include "vlc/vlc.h" // 打开"vlc/vlc.h"。在改文件内的"extern C"前面加入下面内容。 typedef __int64 ssize_t; #include "vlc/vlc.h" // 打开"vlc/vlc.h"。在改文件内的"extern C"前面加入下面内容。 typedef __int64 ssize_t; (3)构建Qt目录,然后在exe目录下将libvlccore.dll、libvlc.dll拷贝进去、将plugins文件也拷贝进去。#include <QMediaPlayer>#include <QMediaPlaylist>libvlc_instance_t* m_pInstance = libvlc_new(0,NULL); //创建实例if(!m_pInstance){ qDebug() << "no vlc"; exit(EXIT_FAILURE);}else{ libvlc_media_player_t* m_pMediaPlayer=libvlc_media_player_new(m_pInstance); //创建媒体 if(!m_pMediaPlayer){ libvlc_release(m_pInstance); exit(EXIT_FAILURE); }}//获取本地文件路径QString filename=QFileDialog::getOpenFileName(this,"打开文件","D:/projects/test","视频文件(*.mp4 *.flv)");if(filename.isEmpty()){ return;} filename.replace("/", "\\"); //必须 或者 filename = QDir::toNativeSeparators(filename); //设置路径libvlc_media_t* m_pMedia = libvlc_media_new_path(m_pInstance,filename.toStdString().c_str());if(m_pMedia){ libvlc_media_parse(m_pMedia); // 有此可以获取时长 libvlc_media_player_set_media(m_pMediaPlayer,m_pMedia); libvlc_media_player_set_hwnd(m_pMediaPlayer, (void*)(ui->video_widget->winId()) ); libvlc_media_release(m_pMedia); m_pMedia=nullptr; libvlc_media_player_play(m_pMediaPlayer);}//获取视频播放状态libvlc_media_player_get_state(m_pMediaPlayer)==libvlc_state_t::libvlc_Playing ;正在播放libvlc_media_player_get_state(m_pMediaPlayer)==libvlc_state_t::libvlc_Paused; 暂停状态libvlc_media_player_get_state(m_pMediaPlayer)==libvlc_state_t::libvlc_Stopped; 停止状态libvlc_media_player_pause(m_pMediaPlayer) ; //暂停libvlc_media_player_stop(m_pMediaPlayer); // 停止管理视频参数需要libvlc_event_manager_t 对象,在创建mediaplayer后,attach 视频seek 和声音调整的回调函数if(m_pMediaPlayer){ libvlc_event_manager_t* m_pEvent_manager=libvlc_media_player_event_manager(m_pMediaPlayer); libvlc_event_attach(m_pEvent_manager,libvlc_MediaPlayerPositionChanged,vlc_callback,this); libvlc_event_attach(m_pEvent_manager,libvlc_MediaPlayerAudioVolume,vlc_callback,this);}void vlc_callback(const struct libvlc_event_t* p_event,void* p_data){ MainWidget* pMain = static_cast<MainWidget*>(p_data);}int duration =libvlc_media_get_duration(m_pMedia); //获取时长,单位毫秒,在释放前获取,这里不是媒体,libvlc_media_player_get_postion(); //获取当前播放时长,百分比libvlc_meida_player_set_postion(m_pMdiaPlayer,[value]/100.0); libvlc_media_player_get_time(pMain->getMediaPlayer())/1000; //获取当前播放的时间单位毫秒libvlc_media_player_get_volume(pMain->getMediaPlayer()); 获取当前播放的声音libvlc_media_player_set_volume(m_pMediaPlayer,value); 设置播放声音播放事件pManager = libvlc_media_player_event_manager(pMediaPlayer);libvlc_event_attach(pManager,libvlc_MediaPlayerPositionChanged,libvlc_callback,this);libvlc_event_attach(pManager,libvlc_MediaPlayerAudioVolume,libvlc_callback,this);多文件播放pMediaListPlayer=libvlc_media_list_player_new(pInstance);//监听事件pManager = libvlc_media_list_player_event_manager(pMediaListPlayer);libvlc_event_attach(pManager,libvlc_MediaPlayerPositionChanged,call_back,this);pMediaList = libvlc_media_list_new(pInstance); for(int i=0;i<filenames.size();i++){ QString filename = QDir::toNativeSeparators(filenames[i]); pMedia = libvlc_media_new_path(pInstance,filename.toStdString().c_str()); libvlc_media_list_add_media(pMediaList,pMedia);}libvlc_media_list_player_set_media_list(pMediaListPlayer,pMediaList);libvlc_media_list_player_set_media_player(pMediaListPlayer,pMediaPlayer);libvlc_media_player_set_hwnd(pMediaPlayer,(void*)ui->media_widget->winId());libvlc_media_list_player_play(pMediaListPlayer);