DropShadowEffect 阻止 QWebEngineView 的显示

问题描述 投票:0回答:0

我正在尝试在

QWebEngineView
元素中显示 URL 的内容,该元素位于
QFrame
中并应用了
DropShadowEffect

但是,这种效果显然导致

QWebEngineView
元素无法刷新内容并保持冻结状态。因为在界面焦点之外执行某些操作之前,
QWebEngineView
元素更新其内容

如果我通过删除

DropShadowEffect
评论这一行,
QWebEngineView
显示没有任何问题

self.shadow_effect([self.ui.frame_render])

Main.py

from PyQt5.QtWidgets import QMainWindow,QApplication,QVBoxLayout,QGraphicsDropShadowEffect,QWidget,QLabel
from PyQt5 import QtWebEngineWidgets
from PyQt5.QtCore import QUrl
from new_ui import Ui_MainWindow

class Main(QMainWindow):
    def __init__(self):
        super(QMainWindow,self).__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
            

        frame_layout = QVBoxLayout()
        self.ui.frame_render.setLayout(frame_layout)

        frame_layout.addWidget(self.show_render())
        

        self.shadow_effect([self.ui.frame_render])

    
        
    def show_render(self):

        graphics_render = QtWebEngineWidgets.QWebEngineView(parent=self.ui.frame_render)
        # Some URL
        graphics_render.setUrl(QUrl("https://www.youtube.com/"))
       
        return graphics_render
        
    
    def shadow_effect(self,widgets=[],blur=25,xofset=-2,yofset=-2):
        for w in widgets:
            effect = QGraphicsDropShadowEffect(w)
            effect.setBlurRadius(blur)
            effect.setXOffset(xofset)
            effect.setYOffset(yofset)
            w.setGraphicsEffect(effect)



app = QApplication([])
m = Main()
m.show()
app.exec_()

new_ui.py

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
        self.stackedWidget.setGeometry(QtCore.QRect(40, 0, 741, 511))
        self.stackedWidget.setObjectName("stackedWidget")
        self.page = QtWidgets.QWidget()
        self.page.setObjectName("page")
        self.frame_render = QtWidgets.QFrame(self.page)
        self.frame_render.setGeometry(QtCore.QRect(250, 20, 381, 201))
        self.frame_render.setStyleSheet("background:white;\n"
"border-radius:50px;")
        self.frame_render.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_render.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_render.setObjectName("frame_render")
        self.frame_one = QtWidgets.QFrame(self.page)
        self.frame_one.setGeometry(QtCore.QRect(150, 300, 401, 211))
        self.frame_one.setStyleSheet("background:red;")
        self.frame_one.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_one.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_one.setObjectName("frame_one")
        self.label = QtWidgets.QLabel(self.page)
        self.label.setGeometry(QtCore.QRect(-40, 110, 631, 261))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("../../Pictures/wallpapersden.com_windows-11-4k-black-blue-art_3840x2160.jpg"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.label.raise_()
        self.frame_render.raise_()
        self.frame_one.raise_()
        self.stackedWidget.addWidget(self.page)
        self.page_2 = QtWidgets.QWidget()
        self.page_2.setObjectName("page_2")
        self.stackedWidget.addWidget(self.page_2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

如何在 QFrame 上应用

QDropShadowEffect
而不影响
QWebEngineView
的行为?

pyqt qwebengineview
© www.soinside.com 2019 - 2024. All rights reserved.