Giter VIP home page Giter VIP logo

Comments (5)

rainzee avatar rainzee commented on June 9, 2024

无法复现,我的代码

import random
import sys

from PyQt5.QtCore import QEasingCurve, QTimer
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget
from qfluentwidgets import FlowLayout


class Demo(QWidget):
    def __init__(self):
        super().__init__()
        self.refreshTimer = QTimer(self)
        self.refreshTimer.timeout.connect(self.refresh)
        self.refreshTimer.start(1000)
        self.mainLyoaut = FlowLayout(self, needAni=True)

        # customize animation
        self.mainLyoaut.setAnimation(250, QEasingCurve.OutQuad)

        self.mainLyoaut.setContentsMargins(30, 30, 30, 30)
        self.mainLyoaut.setVerticalSpacing(20)
        self.mainLyoaut.setHorizontalSpacing(10)

        self.mainLyoaut.addWidget(QPushButton("aiko"))
        self.mainLyoaut.addWidget(QPushButton("刘静爱"))
        self.mainLyoaut.addWidget(QPushButton("柳井爱子"))
        self.mainLyoaut.addWidget(QPushButton("aiko 赛高"))
        self.mainLyoaut.addWidget(QPushButton("aiko 太爱啦😘"))
        self.mainLyoaut.addWidget(QPushButton("aiko"))
        self.mainLyoaut.addWidget(QPushButton("刘静爱"))
        self.mainLyoaut.addWidget(QPushButton("柳井爱子"))
        self.mainLyoaut.addWidget(QPushButton("aiko 赛高"))
        self.mainLyoaut.addWidget(QPushButton("aiko 太爱啦😘"))
        self.mainLyoaut.addWidget(QPushButton("aiko"))
        self.mainLyoaut.addWidget(QPushButton("刘静爱"))
        self.mainLyoaut.addWidget(QPushButton("柳井爱子"))
        self.mainLyoaut.addWidget(QPushButton("aiko 赛高"))
        self.mainLyoaut.addWidget(QPushButton("aiko 太爱啦😘"))
        self.mainLyoaut.addWidget(QPushButton("aiko"))
        self.mainLyoaut.addWidget(QPushButton("刘静爱"))
        self.mainLyoaut.addWidget(QPushButton("柳井爱子"))
        self.mainLyoaut.addWidget(QPushButton("aiko 赛高"))
        self.mainLyoaut.addWidget(QPushButton("aiko 太爱啦😘"))

        self.resize(250, 300)
        self.setStyleSheet('Demo{background: white} QPushButton{padding: 5px 10px; font:15px "Microsoft YaHei"}')

    def refresh(self):
        self.mainLyoaut.takeAllWidgets()
        for i in range(10):
            self.mainLyoaut.addWidget(QPushButton(str(random.randint(0, 100))))


if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Demo()
    w.show()
    app.exec()

from pyqt-fluent-widgets.

lmhHydropower avatar lmhHydropower commented on June 9, 2024

您的代码,我也运行了,确实没有异常问题,但加上滚动区域
self.scrollArea = SmoothScrollArea(self)
self.scrollWidget = QWidget(self.scrollArea)
即可复现出现问题

from pyqt-fluent-widgets.

rainzee avatar rainzee commented on June 9, 2024

你的写法是错误的,按照我这个写,这里没问题,issue可以关了

import random
from typing import Optional

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QApplication, QWidget
from qfluentwidgets import FlowLayout, PushButton, SmoothScrollArea


class SegmentedView(SmoothScrollArea):
    def __init__(self, parent: Optional[QWidget] = None) -> None:
        super().__init__(parent=parent)
        self.refreshTimer = QTimer(self)
        self.refreshTimer.timeout.connect(self.refresh)
        self.refreshTimer.start(1000)
        # instant widget
        self.viewContainer = QWidget()
        # instant layout
        self.viewContainerLayout = FlowLayout(self.viewContainer, needAni=True)
        # init
        self._initWidget()
        self._initLayout()

    def _initWidget(self) -> None:
        self.setWidget(self.viewContainer)
        self.setWidgetResizable(True)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
        self.setViewportMargins(0, 5, 0, 5)
        self.setStyleSheet("border: none;")
        self.resize(400, 300)

    def _initLayout(self) -> None:
        for _ in range(100):
            self.viewContainerLayout.addWidget(PushButton(str(random.randint(0, 100))))

    def refresh(self):
        self.viewContainerLayout.takeAllWidgets()
        self._initLayout()


if __name__ == "__main__":
    app = QApplication([])
    w = SegmentedView()
    w.show()
    app.exec()

from pyqt-fluent-widgets.

lmhHydropower avatar lmhHydropower commented on June 9, 2024

厉害,👍👍👍。问题解决了,但是不知道为什么,可以点播一下吗😀

from pyqt-fluent-widgets.

lmhHydropower avatar lmhHydropower commented on June 9, 2024

关键在于实例化FlowLayout(self.viewContainer, needAni=True, isTight=True)的时候,去掉isTight=True

from pyqt-fluent-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.