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

[Bug]: 主题设置无法传递到subinterface #638

Closed atticus-lv closed 11 months ago

atticus-lv commented 11 months ago

What happened?

rt, 主题设置无法完整传递到自定义的subinterface(可以看到字体是白色的,但背景不是)

image image

Operation System

win11 22631

Python Version

3.10.7

PyQt/PySide Version

5.15.10

PyQt/PySide-Fluent-Widgets Version

1.3.8

How to Reproduce?

使用examples/gallery/window/ms_fluent_window/demo.py 进行测试 把下面提供的文件代码test_interface.py放入demo.py 同一目录下

并替换 demo.py的部分代码

from test_interface import IconInterface
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 = IconInterface(self)
        self.libraryInterface = Widget('library Interface', self)

        self.initNavigation()
        self.initWindow()

Minimum code

# coding:utf-8
from typing import List

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QApplication, QFrame, QVBoxLayout, QLabel, QWidget, QHBoxLayout
from qfluentwidgets import (FluentIcon, IconWidget, FlowLayout, isDarkTheme, setTheme,
                            Theme, applyThemeColor, SmoothScrollArea, SearchLineEdit, StrongBodyLabel, ScrollArea,
                            ImageLabel, CaptionLabel, ElevatedCardWidget,
                            BodyLabel)

from pathlib import Path

# test_interface.py
# 这里放gallery的icon
icon_dir_path = r'C:\Users\atticus\Desktop\test\qt_client\view\test_icon'

class EmojiCard(ElevatedCardWidget):
    """ Emoji card """

    def __init__(self, iconPath: str, parent=None):
        super().__init__(parent)
        self.iconWidget = ImageLabel(iconPath, self)
        self.label = CaptionLabel(Path(iconPath).stem, self)

        self.iconWidget.scaledToHeight(68)

        self.vBoxLayout = QVBoxLayout(self)
        self.vBoxLayout.setAlignment(Qt.AlignCenter)
        self.vBoxLayout.addStretch(1)
        self.vBoxLayout.addWidget(self.iconWidget, 0, Qt.AlignCenter)
        self.vBoxLayout.addStretch(1)
        self.vBoxLayout.addWidget(
            self.label, 0, Qt.AlignHCenter | Qt.AlignBottom)

        self.setFixedSize(168, 176)

class GalleryInterface(ScrollArea):
    """ Gallery interface """

    def __init__(self, title: str, subtitle: str, parent=None):
        """
        Parameters
        ----------
        title: str
            The title of gallery

        subtitle: str
            The subtitle of gallery

        parent: QWidget
            parent widget
        """
        super().__init__(parent=parent)
        self.view = QWidget(self)

        self.flowLayout = FlowLayout(self.view)
        self.flowLayout.setSpacing(6)
        self.flowLayout.setContentsMargins(30, 60, 30, 30)
        self.flowLayout.setAlignment(Qt.AlignVCenter)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setWidget(self.view)
        self.setWidgetResizable(True)

        self.view.setObjectName('view')

        for path in Path(icon_dir_path).glob('*.png'):
            card = EmojiCard(str(path), self)
            self.flowLayout.addWidget(card)

        setTheme(Theme.DARK)

    def scrollToCard(self, index: int):
        """ scroll to example card """
        w = self.vBoxLayout.itemAt(index).widget()
        self.verticalScrollBar().setValue(w.y())

class IconInterface(GalleryInterface):
    """ Icon view """

    def __init__(self, parent=None):
        super().__init__(
            title='test',
            subtitle="qfluentwidgets.common.icon",
            parent=parent
        )
        self.setObjectName('Test Interface')
zhiyiYo commented 11 months ago

得使用样式表设置滚动区域背景以及滚动区域使用的widget背景为透明

atticus-lv commented 11 months ago

谢谢,已解决