如何在 Qt Designer 中添加 QVideoWidget? [英] How to add a QVideoWidget in Qt Designer?

查看:374
本文介绍了如何在 Qt Designer 中添加 QVideoWidget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在蓝框内插入视频(ui图片),但我不知道如何插入视频文件.

I want to insert video in blue box(ui image) but I don't know how to insert video file.

我的代码在这里.我不知道如何添加视频......只知道制作视频播放器的例子......

My code is here. I don't know how to add video... Just know example that make video player ...

import sys

from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import uic
from PyQt5 import QtCore
from PyQt5.QtCore import QDir, Qt, QUrl, pyqtSlot

from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget

from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
        QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget)

dir_audience=''
dir_movie = ''
dir_export = ''
select_emotion = 'happy'

class Form(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.ui = uic.loadUi("highlight_export_form.ui", self)
        self.ui.show()

        self.ui.load_audience.clicked.connect(self.load_audience_clicked)
        self.ui.load_movie.clicked.connect(self.load_movie_clicked)

        self.ui.start_recog.clicked.connect(self.start_recog_clicked)

        self.ui.radio_happy.toggled.connect(self.on_radio_button_toggled)
        self.ui.radio_surprised.toggled.connect(self.on_radio_button_toggled)

    def load_audience_clicked(self, event):
        dir_audience, _ = QFileDialog.getOpenFileName(self, "Open Audience", QDir.homePath())
        self.path_audience.setText(dir_audience)

    def load_movie_clicked(self, event):
        dir_movie, _ = QFileDialog.getOpenFileName(self, "Open Movie", QDir.homePath())
        self.path_movie.setText(dir_movie)

    def start_recog_clicked(self, event):
        self.check_1.setText("start_recognition")

    def on_radio_button_toggled(self):
        if self.radio_happy.isChecked():
            select_emotion='happy'
            self.check_3.setText(select_emotion)

        elif self.radio_surprised.isChecked():
            select_emotion='surprised'
            self.check_3.setText(select_emotion)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = Form()
    sys.exit(app.exec())

感谢您阅读我的问题.

推荐答案

Qt Designer 并没有显示所有的 Qt 小部件,很多时候我们想通过 Qt 添加自己的小部件,为此至少有 2 个解决方案,第一个一个是创建一个插件并加载到Qt Designer,另一个更简单.推广小部件,后者是我将在本答案中展示的内容.

Qt Designer does not show all the Qt widget, and often we want to add our own widget through Qt, for that there are at least 2 solutions, the first is to create a plugin and load it to Qt Designer, and the other is simpler. promote the widget, the latter is what I will show in this answer.

为此,您必须进行某些最小更改,我不知道您在蓝色框中使用的是哪种类型的小部件,但您必须将其更改为容器子菜单中的小部件类型,如图所示如下图:

For this you must make certain minimum changes, I do not know what type of widget is the one you use in the blue box but you must change it to the Widget type that is in the sub-menu of the containers as shown in the following image:

在他们之后你必须右击widget并选择Promote to ...,然后会出现一个对话框,在Promoted class name的部分你必须放置QVideoWidget,并且在Header File的部分你必须放置PyQt5.QtMultimediaWidgets,然后按添加按钮然后Promote:

after them you must right click on the widget and select Promote to ..., then a dialogue will appear, in the part of Promoted class name you must place QVideoWidget, and in the part of Header File you must place PyQt5.QtMultimediaWidgets, then press the add button and then Promote:

之后,您将能够在您的应用程序中使用 QVideoWidget.

After that you will be able to use QVideoWidget within your application.

在下面的链接中有一个例子

In the following link there is an example

这篇关于如何在 Qt Designer 中添加 QVideoWidget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆