forked from DoctorReid/ZenlessZoneZero-OneDragon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
99 lines (71 loc) · 3.26 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# coding:utf-8
import sys
from pathlib import Path
from PySide6.QtCore import QModelIndex, Qt, QRect, QSize
from PySide6.QtGui import QIcon, QPainter, QFont, QColor,QPixmap
from PySide6.QtWidgets import QApplication, QStyleOptionViewItem, QWidget, QHBoxLayout, QVBoxLayout
from qfluentwidgets import (FlipImageDelegate, setTheme, Theme, HorizontalPipsPager, HorizontalFlipView,
VerticalFlipView, getFont)
import requests
class CustomFlipItemDelegate(FlipImageDelegate):
""" Custom flip item delegate """
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
super().paint(painter, option, index)
painter.save()
# draw mask
painter.setBrush(QColor(255, 255, 255, 200))
painter.setPen(Qt.NoPen)
rect = option.rect
rect = QRect(rect.x(), rect.y(), 200, rect.height())
painter.drawRect(rect)
# draw text
painter.setPen(Qt.black)
painter.setFont(getFont(16, QFont.Bold))
painter.drawText(rect, Qt.AlignCenter, '🥰\n硝子酱一级棒卡哇伊')
painter.restore()
class Demo(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
# self.setStyleSheet('Demo{background:rgb(32,32,32)}')
self.flipView = HorizontalFlipView(self)
self.pager = HorizontalPipsPager(self)
# change aspect ratio mode
self.flipView.setAspectRatioMode(Qt.AspectRatioMode.KeepAspectRatio)
# adjust view size
# self.flipView.setItemSize(QSize(320, 180))
# self.flipView.setFixedSize(QSize(320, 180))
# NOTE: use custom delegate
# self.flipView.setItemDelegate(CustomFlipItemDelegate(self.flipView))
# add images
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'])
self.flipView.addImages(self.banners)
self.pager.setPageNumber(self.flipView.count())
# adjust border radius
self.flipView.setBorderRadius(15)
self.pager.currentIndexChanged.connect(self.flipView.setCurrentIndex)
self.flipView.currentIndexChanged.connect(self.pager.setCurrentIndex)
# self.flipView.setCurrentIndex(2)
self.setLayout(QVBoxLayout(self))
self.layout().addWidget(self.flipView, 0, Qt.AlignCenter)
self.layout().addWidget(self.pager, 0, Qt.AlignCenter)
self.layout().setAlignment(Qt.AlignCenter)
self.layout().setSpacing(20)
self.resize(600, 600)
if __name__ == '__main__':
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec_()