【PySide】QtWebEngine web browser opens Flash web page

QWebEngineView loads the flash plug-in and can successfully display Flash, as shown in the figure

Insert image description here

illustrate

Correspondence between QtWebEngine and Chromium versions

Insert image description here

Chromium support for Flash

QtWebEngine module

Qt WebEngine replaces the Qt WebKit module, which was based on the WebKit project but has not been actively synchronized with the upstream WebKit code since Qt 5.2 and has been deprecated in Qt 5.5. For tips on how to change your Qt WebKit widgets application to use Qt WebEngine widgets, see Migrating from Qt WebKit to Qt WebEngine.
Insert image description here

source code

# -*- 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)

download

Source code download link

Reference link

qtwebengine-features
QtWebEngine/ChromiumVersions

Guess you like

Origin blog.csdn.net/qq_25262697/article/details/132331670