无边框,拖拽,阴影:
this->setWindowFlag(Qt::FramelessWindowHint); 设置窗口无边框
void MainWindow::mousePressEvent(QMouseEvent *event){ 鼠标按下事件
mousepos = event->globalPos(); 记录鼠标全局坐标
windowspos = QPoint(this->x(),this->y()); 记录窗口全局坐标
}
void MainWindow::mouseMoveEvent(QMouseEvent *event){ 鼠标移动事件
offset = event->globalPos()-mousepos; 计算偏差值
windowspos +=offset; 窗口新坐标
this->move(windowspos); 移动窗口
mousepos = event->globalPos(); 更新鼠标全局坐标
}
QGraphicsDropShadowEffect * shader = new QGraphicsDropShadowEffect(); 声明一个阴影
shader->setBlurRadius(10); 设置阴影粗细
shader->setColor(Qt::black); 设置阴影颜色
shader->setOffset(0); 设置阴影偏移
ui->widget->setGraphicsEffect(shader); 设置阴影物体
setAttribute(Qt::WA_TranslucentBackground, true); 设置窗体透明(放在ui->setupUi(this)之前)
StyleSheet 样式表:
QPushButton 鼠标无操作时
{
background-color: rgba(241, 26, 26,0); 背景色
border-width:4px; 边框宽度
border-radius:30px; 圆角像素
border-color: rgb(173, 127, 168); 边框颜色
color:blue; 字体颜色
}
QPushButton:hover 鼠标悬停时
{
}
QPushButton:pressed 鼠标按下时
{
}
qss文件是以.qss结尾的文件。内容是qss语句,可以通过函数this->loadStyleSheet(":/qss/myStyleSheet.qss");加载
文件遍历:
filepath = QFileDialog::getExistingDirectory(this,"SelectDirectory","/home/wandong/"); 打开文件对话框
QFileInfoList file = dir.entryInfoList(); 获取目录下的所有文件
dir.exists() 目录是否存在
var.isDir() 文件是否是目录
视频模块:
QT += core gui multimedia multimediawidgets
QMediaPlayer * media =new QMediaPlayer; 声明视频类
QVideoWidget * video =new QVideoWidget; 声明播放界面
video->setParent(this); 设置在主窗口
media->setVideoOutput(video); 设置视频输出窗口
//media->setMedia(QUrl::fromLocalFile("E:/linux/qt/text/Movie/haha.mp4")); 选择文件路径
video->setGeometry(0,0,this->width(),this->height()); 设置显示条件
video->show(); 将界面显示
//media->play(); 播放视频
VLC模块:
下载地址:https://github.com/vlc-qt/vlc-qt/releases
.pro文件添加:
VLC_INSTALL_PATH = D:/Qt/vlclib
INCLUDEPATH += D:/Qt/vlclib/include
CONFIG(debug, debug|release) {
LIBS += -L$$VLC_INSTALL_PATH/lib -lVLCQtCored -lVLCQtWidgetsd -lVLCQtQmld
} else {
LIBS += -L$$VLC_INSTALL_PATH/lib -lVLCQtCore -lVLCQtWidgets -lVLCQtQml
}
简单加载视频播放:
VlcInstance * vlcintance =new VlcInstance(VlcCommon::args(),this) ; 实例一个vlc
VlcMediaPlayer * mediaplayer = new VlcMediaPlayer(vlcintance) ; 声明一个播放器
VlcWidgetVideo * widgetvideo = new VlcWidgetVideo(mediaplayer,this) ; 声明播放器窗口
widgetvideo->setGeometry(0,0,this->width(),this->height()); 设置播放器窗口
mediaplayer->setVideoWidget(widgetvideo); 播放器与窗口关联
mediaplayer->open(&VlcMedia("E:/linux/qt/text/Movie/haha.mp4",true,vlcintance)); 播放器打开文件
mediaplayer->play();//pause stop 播放器播放 暂停 停止
控制声音的组件:VlcWidgetVideo
控制进度的组件:VlcWidgetVolumeSlider
setvolume/volume setmute/mute volume down / up 设置音量 静音 声音大小