在QWebEngineView中观看视频时无法使用fullScreen

时间:2017-11-16 10:05:48

标签: python pyqt fullscreen pyqt5 qwebengineview

使用PyQt5 QWebEngineView,我在观看视频时无法使用fullScreen:

import sys 
from PyQt5 import QtWidgets, QtGui, QtCore 
from PyQt5.QtWebEngineWidgets import * 

app=QtWidgets.QApplication(sys.argv) 
w=QWebEngineView() 
w.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)
w.settings().setAttribute(QWebEngineSettings.JavascriptEnabl‌​ed, True) 
w.settings().setAttribute(QWebEngineSettings.FullScreenSuppo‌​rtEnabled, True)
w.page().fullScreenRequested.connect(QWebEngineFullScreenReq‌​uest.accept) 
w.load(QtCore.QUrl('56.com/w94/play_album-aid-14364505_vid-M‌​TQ3NDUxMjY3.html'))

w.showMaximized() 
app.exec_()

enter image description here

2 个答案:

答案 0 :(得分:0)

QWebEnginePage :: fullScreenRequested信号的参数名为" request"它有一个名为" accept()"的函数。所以你必须致电

  

request.accept()

但是你的代码使用了类型名称(QWebEngineFullScreenRequest),并没有引用这个确切的对象。

https://doc.qt.io/qt-5/qwebenginepage.html#fullScreenRequested

答案 1 :(得分:0)

您可以参考以下代码:

m_webView->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);

connect(m_webView->page(), &QWebEnginePage::fullScreenRequested, this, [this] 
(QWebEngineFullScreenRequest fullScreenRequest) {
        fullScreenRequest.accept();
        qDebug()<<"UI: fullScreenRequested: "<<fullScreenRequest.toggleOn()<<endl;
    });