视频小部件自行调整大小

时间:2018-06-06 15:33:11

标签: python python-3.x pyqt pyqt5

我使用PyQt5相当新,并且一直用来创建我自己的媒体播放器,我遇到的问题是视频小部件在我播放或暂停时自行调整大小,我也可以将主窗口设置为与正在播放的视频大小相同,如何阻止它调整大小?

import sys
from PyQt5 import QtWidgets,QtGui
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtCore import QDir, Qt, QUrl

class Window(QtWidgets.QMainWindow):

def __init__(self):
    super().__init__()
    self.k=0
    self.init_ui()

def init_ui(self):
    self.play=QtWidgets.QPushButton(self)
    self.stop=QtWidgets.QPushButton(self)
    self.play.setText('Play')
    self.stop.setText('Stop')
    self.play.move(0,700)
    self.stop.move(80,700)
    self.setWindowTitle('SyncMedia')
    menu = self.menuBar()
    file = menu.addMenu(' &File ')
    open =QtWidgets.QAction(QtGui.QIcon('open.png'), '&Open', self)
    file.addAction(open)
    #file.addAction(close)
    self.play.clicked.connect(self.play_click)
    self.mediaPlayer =QMediaPlayer(None, QMediaPlayer.VideoSurface)
    self.videoWidget = QVideoWidget()
    wid =QtWidgets.QWidget(self)
    self.setCentralWidget(wid)
    controlLayout=QtWidgets.QHBoxLayout()
    controlLayout.addWidget(self.play)
    controlLayout.addWidget(self.stop)
    layout =QtWidgets.QVBoxLayout()
    layout.addWidget(self.videoWidget)
    layout.addLayout(controlLayout)
    wid.setLayout(layout)
    self.videoWidget.move(500,500)
    self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile("(videofilepath")))
    self.mediaPlayer.setVideoOutput(self.videoWidget)
    self.videoWidget.show()
    self.mediaPlayer.play()
    self.show()
def play_click(self):
    if(self.k==1):
        self.mediaPlayer.play()
        self.play.setText('Pause')
        self.k=0
    elif(self.k==0):
        self.mediaPlayer.pause()
        self.play.setText('Play')
        self.k=1

app=QtWidgets.QApplication(sys.argv)
window=Window()
sys.exit(app.exec_())

0 个答案:

没有答案