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
4.98k stars 464 forks source link

[Bug]: 继承'SplitFluentWindow'加载html会导致侧边栏显示异常,图标消失 #879

Closed tommyUU closed 1 month ago

tommyUU commented 1 month ago

What happened?

子窗口容器加载html后,会导致侧边栏图标消失

Operation System

Windows11

Python Version

3.12.0

PyQt/PySide Version

PySide6

PyQt/PySide-Fluent-Widgets Version

PySide6-Fluent-Widgets 1.5.6

How to Reproduce?

不加载有html的容器侧边栏显示正常,反之侧边栏的图标消失 image 我注意到窗体圆角部分消失了 注释掉含有html的子窗口 显示就正常了 image

Minimum code

import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon, QGuiApplication
from PySide6.QtWidgets import QApplication, QWidget
from qfluentwidgets import SplitFluentWindow, FluentIcon, NavigationAvatarWidget, NavigationItemPosition, setTheme, \
    Theme
from page1_interface import BackGround1
from page2_interface import BackGround2
from page4_interface import MusicPage
from page3_interface import SettingsPage

class Demo(SplitFluentWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('小红书自动算法')
        self.setFixedSize(1440, 800)

        self.setWindowFlags(self.windowFlags())

        self.subpage1 = BackGround1(self)
        self.subpage2 = BackGround2(self)
        # self.subpage_music = MusicPage(self)

        self.night = SettingsPage(self)

        if hasattr(self.night, 'SwitchButton'):
            self.night.SwitchButton.checkedChanged.connect(self.switch_night)

        self.addSubInterface(self.subpage1, FluentIcon.HOME, '工作区')
        self.addSubInterface(self.subpage2, FluentIcon.PIE_SINGLE, 'kanban')
        # self.addSubInterface(self.subpage_music, FluentIcon.MUSIC, '音乐')
        self.addSubInterface(self.night, FluentIcon.SETTING, '设置', position=NavigationItemPosition.BOTTOM)

        # 添加其他导航项
        self.navigationInterface.addWidget(
            routeKey='avatar',
            widget=NavigationAvatarWidget('test', 'img/1.png'),
            position=NavigationItemPosition.BOTTOM
        )

    def switch_night(self, is_checked: bool):
        if is_checked:
            setTheme(Theme.DARK)
        else:
            setTheme(Theme.LIGHT)

    def switch_music(self):
        self.setCurrentSubInterface(self.subpage_music)

if __name__ == '__main__':
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    setTheme(Theme.LIGHT)
    app = QApplication(sys.argv)
    w = Demo()
    w.show()
    app.exec()

import os
import sys

from PySide6.QtCore import Qt, QThread, Signal, QUrl
from PySide6.QtWebEngineCore import QWebEngineSettings
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout
from bk4_music import Ui_Form

# class LoadMusicThread(QThread):
#     music_loaded_signal = Signal(str)
# 
#     def run(self):
#         self.music_loaded_signal.emit("加载完成")  # 

class MusicPage(QWidget, Ui_Form):

    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.setupUi(self)

        self.web_view = QWebEngineView()
        self.setup_web_view()

        self.set_web_engine_attributes()

    def set_web_engine_attributes(self):
        self.web_view.settings().setAttribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls, True)
        self.web_view.settings().setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True)
        self.web_view.settings().setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True)

    def setup_web_view(self):
        page_widget = self.CardWidget
        layout = QVBoxLayout(page_widget)
        layout.addWidget(self.web_view)
        page_widget.setLayout(layout)

        html_path = os.path.join(os.path.dirname(__file__), 'html', 't1.html')
        url = QUrl.fromLocalFile(html_path)
        self.web_view.load(url)

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

    app = QApplication(sys.argv)
    w = MusicPage()
    w.show()
    app.exec()