zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.65k stars 544 forks source link

[Bug]: (FramelessWebEngineView) and (QWebEngineView) are messing up the (FluentWindow) theme #673

Closed AliMostafaRadwan closed 10 months ago

AliMostafaRadwan commented 10 months ago

What happened?

if i added a QWebEngineView or even after using FramelessWebEngineView in FluentWindow class, the whole theme get broken image

without the QWebEngineView or FramelessWebEngineView (expected) : image

Operation System

Windows 11 Pro, 22H2

Python Version

3.10

PyQt/PySide Version

PyQt5==5.15.9 PyQt5-Qt5==5.15.2

PyQt/PySide-Fluent-Widgets Version

PyQt-Fluent-Widgets==1.4.1 PyQt5-Frameless-Window==0.3.7

How to Reproduce?

As long as you add QWebEngineView to any subpage and display it in various FluentWindow, it will appear. It is normal to display the subpage alone.

Minimum code

# coding:utf-8
import sys

from PyQt5.QtCore import Qt, QUrl, QTimer
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QFrame, QVBoxLayout, QHBoxLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, FluentWindow,
                            NavigationAvatarWidget, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF, MSFluentTitleBar, isDarkTheme
from pathlib import Path

from PyQt5.QtCore import Qt, QSize
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QGridLayout
from qfluentwidgets import (PrimaryPushButton,
                            setTheme, Theme)
from qfluentwidgets import setTheme, Theme,SplashScreen
from qframelesswindow.webengine import FramelessWebEngineView
from CustomWebView import CustomWebView
import subprocess
from TableWidget import CustomTableWidget
import json
from FolderSelector import FolderSelectionWidget
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget

from qfluentwidgets import InfoBar, setTheme, Theme, InfoBarPosition, LargeTitleLabel, DisplayLabel,CaptionLabel

from qfluentwidgets import (FlipImageDelegate, Theme, HorizontalPipsPager, HorizontalFlipView,
                            VerticalFlipView, getFont)

class WebView(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        # self.setWindowTitle("My App")
        self.webview = FramelessWebEngineView(self)
        # WebUrl = "http://localhost:8501/"
        WebUrl = "https://qfluentwidgets.com/"
        self.webview.load(QUrl(WebUrl))

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.webview)
        self.setLayout(self.layout)
        self.setObjectName("WebView")

 #other code.......

 class Window(FluentWindow):

    def __init__(self):
        super().__init__()
        self.setMicaEffectEnabled(True)
        # create sub interface
        self.mainInterface = WebView()
        self.homeInterface = TableWidget()
        self.musicInterface = FolderSelection()
        self.videoInterface = ImageDis()
        self.folderInterface = Widget('Folder Interface', self)
        self.settingInterface = Widget('Setting Interface', self)
        self.albumInterface = Widget('Album Interface', self)
        self.albumInterface1 = Widget('Album Interface 1', self)
        self.albumInterface2 = Widget('Album Interface 2', self)
        self.albumInterface1_1 = Widget('Album Interface 1-1', self)

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):

        self.addSubInterface(self.mainInterface, FIF.HOME, 'Main')
        self.addSubInterface(self.homeInterface, FIF.LABEL, 'Answer Key')

        self.addSubInterface(self.musicInterface, FIF.CHECKBOX, 'Grading')
        self.addSubInterface(self.videoInterface, FIF.PHOTO, 'Image Preview')

        self.navigationInterface.addSeparator()

        self.addSubInterface(self.albumInterface, FIF.ALBUM, 'Albums', NavigationItemPosition.SCROLL)
        self.addSubInterface(self.albumInterface1, FIF.ALBUM, 'Album 1', parent=self.albumInterface)
        self.addSubInterface(self.albumInterface1_1, FIF.ALBUM, 'Album 1.1', parent=self.albumInterface1)
        self.addSubInterface(self.albumInterface2, FIF.ALBUM, 'Album 2', parent=self.albumInterface)
        self.addSubInterface(self.folderInterface, FIF.FOLDER, 'Folder library', NavigationItemPosition.SCROLL)

        # add custom widget to bottom
        self.navigationInterface.addWidget(
            routeKey='avatar',
            widget=NavigationAvatarWidget('zhiyiYo', 'resource\shoko.png'),
            onClick=self.showMessageBox,
            position=NavigationItemPosition.BOTTOM,
        )

        self.addSubInterface(self.settingInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM)

        # add badge to navigation item
        # item = self.navigationInterface.widget(self.homeInterface.objectName())
        # InfoBadge.attension(
        #     text=len(metadata),
        #     parent=item.parent(),
        #     target=item,
        #     position=InfoBadgePosition.NAVIGATION_ITEM
        # )

    def initWindow(self):
        self.setMicaEffectEnabled(True)

        self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))

        self.splashScreen = SplashScreen(self.windowIcon(), self)

        self.splashScreen.setIconSize(QSize(102, 102))
        self.splashScreen.show()
        QTimer.singleShot(20, self.splashScreen.close) #200

        self.resize(1000, 750)
        self.setWindowTitle('GradVision')
        self.updateFrameless()
        self.setMicaEffectEnabled(True)
        desktop = QApplication.screens()[0].availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w//2 - self.width()//2, h//2 - self.height()//2)

        # self.setStyleSheet("background-image: url(resource\shoko.png);")

    def showMessageBox(self):
        w = MessageBox(
            'This is a test🥰',
            '个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
            self
        )
        w.yesButton.setText('Yes')
        w.cancelButton.setText('No')
        if w.exec():
            QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))

    #theme
    setTheme(Theme.DARK)

if __name__ == '__main__':
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    # setTheme(Theme.DARK)

    app = QApplication(sys.argv)
    w = Window()
    w.show()
    app.exec_()
AIjie-sen commented 2 months ago

我现在也遇到了相同的问题,解决方法是什么