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.61k stars 541 forks source link

引入网页,界面颜色异常 #986

Closed OnlyHiu closed 1 week ago

OnlyHiu commented 1 week ago

What happened?

在ms_fluent_window的demo里面,加了网页的控件,导致页面变黑。期望是正常显示

Operation System

window11

Python Version

3.12.4

PyQt/PySide Version

Pyqt5 5.15.11

PyQt/PySide-Fluent-Widgets Version

1.6.6

How to Reproduce?

examples/window/ms_fluent_window/demo.py 初始化: def init(self, text: str, parent=None): super().init(parent=parent) self.label = SubtitleLabel(text, self) self.hBoxLayout = QHBoxLayout(self)

setFont(self.label, 24)

    # self.label.setAlignment(Qt.AlignCenter)
    # self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
    self.web = QtWebEngineWidgets.QWebEngineView(self)
    self.web.setUrl(QUrl("https://fanyi.baidu.com/mtpe-individual/multimodal#/"))
    self.hBoxLayout.addWidget(self.web)
    self.setObjectName(text.replace(' ', '-'))

Minimum code

# coding:utf-8
import sys

from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication, QFrame, QHBoxLayout, QGridLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, MSFluentWindow,
                            NavigationAvatarWidget, qrouter, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWebEngineWidgets

class Widget(QFrame):

    def __init__(self, text: str, parent=None):
        super().__init__(parent=parent)
        self.label = SubtitleLabel(text, self)
        self.hBoxLayout = QHBoxLayout(self)
        # setFont(self.label, 24)
        # self.label.setAlignment(Qt.AlignCenter)
        # self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
        self.web = QtWebEngineWidgets.QWebEngineView(self)
        self.web.setUrl(QUrl("https://fanyi.baidu.com/mtpe-individual/multimodal#/"))
        self.hBoxLayout.addWidget(self.web)
        self.setObjectName(text.replace(' ', '-'))

class Window(MSFluentWindow):

    def __init__(self):
        super().__init__()

        # create sub interface
        self.homeInterface = Widget('Home Interface', self)
        self.appInterface = Widget('Application Interface', self)
        self.videoInterface = Widget('Video Interface', self)
        self.libraryInterface = Widget('library Interface', self)

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.homeInterface, FIF.HOME, '主页', FIF.HOME_FILL)
        self.addSubInterface(self.appInterface, FIF.APPLICATION, '应用')
        self.addSubInterface(self.videoInterface, FIF.VIDEO, '视频')

        self.addSubInterface(self.libraryInterface, FIF.BOOK_SHELF, '库', FIF.LIBRARY_FILL, NavigationItemPosition.BOTTOM)
        self.navigationInterface.addItem(
            routeKey='Help',
            icon=FIF.HELP,
            text='帮助',
            onClick=self.showMessageBox,
            selectable=False,
            position=NavigationItemPosition.BOTTOM,
        )

        self.navigationInterface.setCurrentItem(self.homeInterface.objectName())

    def initWindow(self):
        self.resize(900, 700)
        self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
        self.setWindowTitle('PyQt-Fluent-Widgets')

        desktop = QApplication.desktop().availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w//2 - self.width()//2, h//2 - self.height()//2)

    def showMessageBox(self):
        w = MessageBox(
            '支持作者🥰',
            '个人开发不易,如果这个项目帮助到了您,可以考虑请作者喝一瓶快乐水🥤。您的支持就是作者开发和维护项目的动力🚀',
            self
        )
        w.yesButton.setText('来啦老弟')
        w.cancelButton.setText('下次一定')

        if w.exec():
            QDesktopServices.openUrl(QUrl("https://afdian.net/a/zhiyiYo"))

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_()
AlexZhu2001 commented 1 week ago

同版本下暂时无法复现,能否提供截图,如果是进入了深色模式(Theme.Dark),是不是跟随系统主题导致的呢,是否可以通过setTheme复原

zhiyiYo commented 1 week ago

官网文档写了