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]: flipView设置圆角时,切换动画的过程中并不是圆角 #995

Open yokuminto opened 3 days ago

yokuminto commented 3 days ago

What happened?

设置圆角后,只有停止动画时才是圆角 以及,如果这样子写的话,flipView会把卡片的圆角也占据了.不知道有没有好的写法

Operation System

Windows11 23H2

Python Version

3.10.9

PyQt/PySide Version

pyside6==6.7.2

PyQt/PySide-Fluent-Widgets Version

PySide6-Fluent-Widgets==1.6.6

How to Reproduce?

猜想:可能是动画过程中是单纯的平移,而圆角实际上是绘制图片时设置的 期望:全程动画保持圆角 这是最小示例的演示效果

动画

新的演示效果

动画

Minimum code

import sys
import requests
from PySide6.QtCore import Qt, QSize, QRect,QModelIndex,QRectF,QSizeF
from PySide6.QtGui import QPixmap, QPainter,QPainterPath
from PySide6.QtWidgets import QVBoxLayout,QStyleOptionViewItem
from qfluentwidgets import SimpleCardWidget, HorizontalFlipView,FlipImageDelegate
import webbrowser

class NoticeCard(SimpleCardWidget):
    def __init__(self):
        super().__init__()

        self.setFixedSize(QSize(345, 160))
        self.mainLayout = QVBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)

        response = requests.get("https://hyp-api.mihoyo.com/hyp/hyp-connect/api/getGameContent?launcher_id=jGHBHlcOq1&game_id=x6znKlJ0xK&language=zh-cn").json()
        banners = response['data']['content']['banners']

        self.banners = []
        self.urls = []

        for banner in banners:
            pixmap = QPixmap()
            pixmap.loadFromData(requests.get(banner['image']['url']).content)
            self.banners.append(pixmap)
            self.urls.append(banner['image']['link'])

        # 创建 flipView
        self.flipView = HorizontalFlipView(self)
        self.flipView.addImages(self.banners)
        self.flipView.setAspectRatioMode(Qt.AspectRatioMode.KeepAspectRatio)
        self.flipView.setItemSize(QSize(345, 160))
        self.flipView.setFixedSize(QSize(345, 160))
        self.flipView.setBorderRadius(10)
        self.flipView.itemClicked.connect(self.open_link)

        self.mainLayout.addWidget(self.flipView)

    def open_link(self):
        webbrowser.open(self.urls[self.flipView.currentIndex()])
zhiyiYo commented 2 days ago

解决不了,这个是被视口挡住了

yokuminto commented 2 days ago

解决不了,这个是被视口挡住了

可以通过蒙版解决吗?刚刚看到一个可能解决的方案:https://blog.csdn.net/away_1997/article/details/122740762

yokuminto commented 2 days ago

解决不了,这个是被视口挡住了

可以通过蒙版解决吗?刚刚看到一个可能解决的方案:https://blog.csdn.net/away_1997/article/details/122740762

我实现了一个生效的示例,能够正常运行,不过存在一些锯齿(就效果来说目前够用了)

        # 创建 flipView
        self.flipView = HorizontalFlipView(self)
        self.flipView.addImages(self.banners)
        self.flipView.setAspectRatioMode(Qt.AspectRatioMode.KeepAspectRatio)
        self.flipView.setItemSize(QSize(345, 160))
        self.flipView.setFixedSize(QSize(345, 160))
        self.flipView.itemClicked.connect(self.open_banner_link)

        # 实现遮罩
        path = QPainterPath()
        path.addRoundedRect(self.flipView.rect(), 10, 10, Qt.SizeMode.AbsoluteSize)
        region = QRegion(path.toFillPolygon().toPolygon())
        self.flipView.setMask(region)

        self.mainLayout.addWidget(self.flipView)
rainzee commented 1 day ago

我觉得这个可能不算是个 bug