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]: ExpandLayout 中错误的 y 值计算? #941

Closed XiaoYouChR closed 2 months ago

XiaoYouChR commented 2 months ago

What happened?

在 PFW 的 ExpandLayout 中的 __doLayout 函数中 y 值的计算似乎被意外地加上了 margin.bottom() , 导致了整体控件的向下偏移

Operation System

Manjaro Linux 6.9.12-1-MANJARO X11

Python Version

3.11.9 64-bit

PyQt/PySide Version

PySide6 6.7.2

PyQt/PySide-Fluent-Widgets Version

v1.6.0

How to Reproduce?

ExpandLayout 里的控件明显向下偏

image

Minimum code

from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout, QFrame
from qfluentwidgets import ExpandLayout, ScrollArea, PrimaryPushButton, PushButton, MSFluentWindow, \
    TitleLabel, CardWidget

from qfluentwidgets import FluentIcon as FIF

class MainWindow(MSFluentWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("Fluent Window")
        self.setMinimumSize(800, 600)

        self.homeInterface = HomeInterface(self)
        self.addSubInterface(self.homeInterface, FIF.HOME, "Home")

class HomeInterface(ScrollArea):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setObjectName("homeInterface")

        self.setupUi()

        self.setWidget(self.scrollWidget)
    def setupUi(self):
        self.setFrameShape(QFrame.NoFrame)

        self.scrollWidget = QWidget()
        self.scrollWidget.setObjectName("scrollWidget")

        self.expandLayout = ExpandLayout(self.scrollWidget)
        self.expandLayout.setObjectName("expandLayout")
        self.expandLayout.setSpacing(0)

        print(self.expandLayout.contentsMargins())

        # TaskCard
        self.taskCard = CardWidget(self.scrollWidget)
        self.taskCard.setObjectName("taskCard")
        self.taskCard.setMinimumSize(300, 100)
        self.expandLayout.addWidget(self.taskCard)

        # ToolsBar
        self.toolsBar = QWidget(self.scrollWidget)
        self.toolsBar.setObjectName("toolsBar")
        self.toolsBar.resize(447, 60)

        self.horizontalLayout = QHBoxLayout(self.toolsBar)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)

        self.toolsBar.setLayout(self.horizontalLayout)

        self.allStartButton = PrimaryPushButton(self.toolsBar)
        self.allStartButton.setObjectName(u"allStartButton")
        self.allStartButton.setIcon(FIF.PLAY)
        self.horizontalLayout.addWidget(self.allStartButton)

        self.allPauseButton = PushButton(self.toolsBar)
        self.allPauseButton.setObjectName(u"allPauseButton")
        self.allPauseButton.setIcon(FIF.STOP_WATCH)
        self.horizontalLayout.addWidget(self.allPauseButton)

        self.expandLayout.addWidget(self.toolsBar)

        self.noTaskLabel = TitleLabel("NoTask", self.scrollWidget)
        self.noTaskLabel.setObjectName("noTaskLabel")
        self.expandLayout.addWidget(self.noTaskLabel)
        self.scrollWidget.setMinimumWidth(600)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec())
zhiyiYo commented 2 months ago

已修复此问题