本文介绍了如何通过 mpylayer 将视频嵌入到 QWidget 框架中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 PyQt4 中通过 mpylayer 嵌入视频QWidget (或到它的子类).如果是这样,您能否提供一个最小的工作示例.

Is it possible in PyQt4 to embed a video via mpylayer into a QWidget (or into a subclass of it). If so, could you provide a minimal working example.

推荐答案

有关嵌入 MPlayer 的 Qt Widget 的完整示例,请尝试 qmpwidget.

For a complete example of a Qt Widget that embeds MPlayer, try qmpwidget.

但这里有一个最小的 PyQt 演示,可以帮助您入门:

But here's a minimal PyQt demo to get you started:

import mpylayer
from PyQt4 import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.container = QtGui.QWidget(self)
        self.container.setStyleSheet('background: black')
        self.button = QtGui.QPushButton('Open', self)
        self.button.clicked.connect(self.handleButton)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.container)
        layout.addWidget(self.button)
        self.mplayer = mpylayer.MPlayerControl(
            'mplayer', ['-wid', str(self.container.winId())])

    def handleButton(self):
        path = QtGui.QFileDialog.getOpenFileName()
        if not path.isEmpty():
            self.mplayer.loadfile(unicode(path))

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.resize(640, 480)
    window.show()
    sys.exit(app.exec_())

(注意:此演示仅在 Linux 上测试过)

(NB: this demo has only been tested on Linux)

这篇关于如何通过 mpylayer 将视频嵌入到 QWidget 框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:21