2

我正在尝试在 QWebEngineView 中嵌入 youtube 视频,视频加载正常但全屏按钮被禁用,并显示此消息“全屏不可用”,即使嵌入代码确实具有“allowfullscreen”

代码片段:

web = QWebEngineView()
htmlString = """
            <iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
             """
web.setHtml(htmlString, QUrl(baseUrl))
4

1 回答 1

2

要启用全屏,必须启用FullScreenSupportEnabled属性并接受页面的fullScreenRequested顺序。

if __name__ == '__main__':
    app = QApplication(sys.argv)
    web = QWebEngineView()
    web.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
    web.page().fullScreenRequested.connect(lambda request: request.accept())
    baseUrl = "local"
    htmlString = """
            <iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
             """
    web.setHtml(htmlString, QUrl(baseUrl))

    web.show()
    sys.exit(app.exec_())

截屏:

在此处输入图像描述

于 2017-10-31T15:05:10.990 回答