Pyqt报错:arguments did not match any overloaded call
Pyqt报错:arguments did not match any overloaded call详细报错信息:TypeError: arguments did not match any overloaded call:setVideoOutput(self, QVideoWidget): argument 1 has unexpected type 'QWidget'setVideoOutp
Pyqt报错:arguments did not match any overloaded call
详细报错信息:
TypeError: arguments did not match any overloaded call:
setVideoOutput(self, QVideoWidget): argument 1 has unexpected type 'QWidget'
setVideoOutput(self, QGraphicsVideoItem): argument 1 has unexpected type 'QWidget'
setVideoOutput(self, QAbstractVideoSurface): argument 1 has unexpected type 'QWidget'
setVideoOutput(self, Iterable[QAbstractVideoSurface]): argument 1 has unexpected type 'QWidget'
Process finished with exit code 0
解决方案:
将QtWidgets.QWidget
更换为QVideoWidget
:
修改之后:
原本:
源代码(修改之后的):
GUI:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '.\untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtMultimediaWidgets import QVideoWidget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1134, 858)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.wgt_video = QVideoWidget(self.centralwidget)
self.wgt_video.setGeometry(QtCore.QRect(230, 90, 641, 451))
self.wgt_video.setObjectName("wgt_video")
self.btn_open = QtWidgets.QPushButton(self.centralwidget)
self.btn_open.setGeometry(QtCore.QRect(240, 650, 93, 28))
self.btn_open.setObjectName("btn_open")
self.btn_play = QtWidgets.QPushButton(self.centralwidget)
self.btn_play.setGeometry(QtCore.QRect(490, 650, 93, 28))
self.btn_play.setObjectName("btn_play")
self.btn_stop = QtWidgets.QPushButton(self.centralwidget)
self.btn_stop.setGeometry(QtCore.QRect(760, 650, 93, 28))
self.btn_stop.setObjectName("btn_stop")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1134, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.btn_open.setText(_translate("MainWindow", "打开"))
self.btn_play.setText(_translate("MainWindow", "播放"))
self.btn_stop.setText(_translate("MainWindow", "暂停"))
main:
from PyQt5.QtWidgets import *
from PyQt5.QtMultimedia import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtMultimediaWidgets import QVideoWidget
from GUI import Ui_MainWindow
import sys
class myMainWindow( Ui_MainWindow,QMainWindow):
def __init__(self):
super(Ui_MainWindow, self).__init__()
self.setupUi(self)
self.player = QMediaPlayer()
self.player.setVideoOutput(self.wgt_video) # 设置播放设备。播放设备是视频窗口对象
self.btn_open.clicked.connect(self.openVideoFile) # 打开视频文件按钮
self.btn_play.clicked.connect(self.playVideo) # play
self.btn_stop.clicked.connect(self.pauseVideo) # pause
self.player.positionChanged.connect(self.changeSlide) # change Slide
def openVideoFile(self):
self.player.setMedia(QMediaContent(QFileDialog.getOpenFileUrl()[0])) # 选取视频文件
self.player.play() # 播放视频
def playVideo(self):
self.player.play()
def pauseVideo(self):
self.player.pause()
def changeSlide(self, position):
self.vidoeLength = self.player.duration() + 0.1
self.sld_video.setValue(round((position / self.vidoeLength) * 100))
self.lab_video.setText(str(round((position / self.vidoeLength) * 100, 2)) + '%')
if __name__ == "__main__":
app = QApplication(sys.argv) # 创建QApplication对象,作为GUI主程序入口
vieo_gui = myMainWindow()
vieo_gui.show()
sys.exit(app.exec_()) # 循环中等待退出程序
吐槽:
最近因为比赛原因刚学qt,想着快,就直接入手别人的代码改,但是遇到很多问题;上面这个问题是,我用qt的designer画了一个播放器界面,播放器的区域用了Qlebal这个类,然后导出为py文件,主程序中调用,就出现了这个问题; 经某qt大哥指点,是:setVideoOutput 这个函数不认识设置的widget对象,这应该是我设置错模板类了?后续继续学习…
更多推荐
所有评论(0)