I am a beginner in Qt. But following some tutorials I created a UI in qt designer which would display a live stream video. I have read that in order to add video i need to promote widget to a QVideoWidget. Then I convert the .ui to a .py file to access it using python language. The thing is once i have done that i dont know how to put the video in the widget that i made in the ui. Thank you.
The code below show the GUI.py file. I am importing it in another file where I would code it show the video. but dont know how thanks
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'facebio.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(558, 388)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.listWidget = QtWidgets.QListWidget(self.centralwidget)
self.listWidget.setGeometry(QtCore.QRect(280, 10, 261, 221))
self.listWidget.setObjectName("listWidget")
self.listWidget_2 = QtWidgets.QListWidget(self.centralwidget)
self.listWidget_2.setGeometry(QtCore.QRect(20, 240, 521, 101))
self.listWidget_2.setObjectName("listWidget_2")
self.widget = QVideoWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(20, 10, 241, 221))
self.widget.setObjectName("widget")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
from PyQt5.QtMultimediaWidgets import QVideoWidget
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…