QString path = QFileDialog::getOpenFileName(this, tr("选择视频"), ".", tr("Image Files(*.flv *.mp4)"));//得到视频路径
mediaPlayer = new QMediaPlayer();
layout_video = new QVBoxLayout;
videoWidget = new QVideoWidget();
layout_video->setMargin(1);
//根据label_player尺寸设置播放区域
videoWidget->resize(ui->label_player->size());
layout_video->addWidget(videoWidget);
ui->label_player->setLayout(layout_video);
mediaPlayer->setVideoOutput(videoWidget);
mediaPlayer->setMedia(QUrl::fromLocalFile(path));
mediaPlayer->play();