QWebEngineView 加载 flash插件,可成功显示Flash,如图
说明
QtWebEngine与Chromium版本对应关系
Chromium对Flash的支持
QtWebEngine模块
Qt WebEngine取代了Qt WebKit模块,后者基于WebKit项目,但自Qt 5.2以来没有主动与上游WebKit代码同步,并且在Qt 5.5中已被弃用。有关如何更改Qt WebKit widgets应用程序以使用Qt WebEngine widgets的提示,请参阅从Qt WebKit到Qt WebEngine的移植。
源代码
# -*- coding: utf-8 -*-
"""
@File : pyside_2.py
@Time : 2023/8/17 0:11
@Author : KmBase
@Version : 1.0
@Contact :
@Desc : None
"""
import sys
from pathlib import Path
from PySide2 import QtWebEngineWidgets
from PySide2.QtCore import QUrl, Qt
from PySide2.QtWebEngineWidgets import QWebEngineView
from PySide2.QtWidgets import QMainWindow, QApplication, QHBoxLayout, QSplitter, QWidget
class WebBrowser(QMainWindow):
def __init__(self):
super().__init__()
# 设置窗口标题
self.setWindowTitle("Browser")
self.main_widget = QWidget()
self.main_layout = QHBoxLayout(self.main_widget)
self.setCentralWidget(self.main_widget)
self.splitter = QSplitter(Qt.Horizontal)
self.view = QWebEngineView()
self.dev_view = QWebEngineView()
self.splitter.addWidget(self.view)
self.splitter.addWidget(self.dev_view)
self.splitter.setStretchFactor(1, 1)
self.main_layout.addWidget(self.splitter)
# 加载开发者页面
self.view.load(QUrl("http://www.ultrasounds.com/"))
self.view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.PluginsEnabled, True)
self.view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.JavascriptEnabled, True)
# 将QWebEngineView添加到主窗口的中心区域
self.view.page().setDevToolsPage(self.dev_view.page())
self.main_layout.addWidget(self.splitter)
下载
源代码下载链接
参考链接
qtwebengine-features
QtWebEngine/ChromiumVersions