Skip to content

Commit 305efd6

Browse files
committed
update
1 parent 880fc81 commit 305efd6

31 files changed

+9436
-0
lines changed

QFlowLayout/Lib/__init__.py

Whitespace-only changes.

QFlowLayout/Lib/flowlayout.py

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/usr/bin/env python
2+
3+
4+
#############################################################################
5+
##
6+
# Copyright (C) 2013 Riverbank Computing Limited.
7+
# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8+
# All rights reserved.
9+
##
10+
# This file is part of the examples of PyQt.
11+
##
12+
# $QT_BEGIN_LICENSE:BSD$
13+
# You may use this file under the terms of the BSD license as follows:
14+
##
15+
# "Redistribution and use in source and binary forms, with or without
16+
# modification, are permitted provided that the following conditions are
17+
# met:
18+
# * Redistributions of source code must retain the above copyright
19+
# notice, this list of conditions and the following disclaimer.
20+
# * Redistributions in binary form must reproduce the above copyright
21+
# notice, this list of conditions and the following disclaimer in
22+
# the documentation and/or other materials provided with the
23+
# distribution.
24+
# * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
25+
# the names of its contributors may be used to endorse or promote
26+
# products derived from this software without specific prior written
27+
# permission.
28+
##
29+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
40+
# $QT_END_LICENSE$
41+
##
42+
#############################################################################
43+
44+
45+
from PyQt5.QtCore import QPoint, QRect, QSize, Qt
46+
from PyQt5.QtWidgets import (QApplication, QLayout, QPushButton, QSizePolicy,
47+
QWidget)
48+
49+
50+
class Window(QWidget):
51+
def __init__(self):
52+
super(Window, self).__init__()
53+
54+
flowLayout = FlowLayout()
55+
flowLayout.addWidget(QPushButton("Short"))
56+
flowLayout.addWidget(QPushButton("Longer"))
57+
flowLayout.addWidget(QPushButton("Different text"))
58+
flowLayout.addWidget(QPushButton("More text"))
59+
flowLayout.addWidget(QPushButton("Even longer button text"))
60+
self.setLayout(flowLayout)
61+
62+
self.setWindowTitle("Flow Layout")
63+
64+
65+
class FlowLayout(QLayout):
66+
def __init__(self, parent=None, margin=0, spacing=-1):
67+
super(FlowLayout, self).__init__(parent)
68+
69+
if parent is not None:
70+
self.setContentsMargins(margin, margin, margin, margin)
71+
72+
self.setSpacing(spacing)
73+
74+
self.itemList = []
75+
76+
def __del__(self):
77+
item = self.takeAt(0)
78+
while item:
79+
item = self.takeAt(0)
80+
81+
def addItem(self, item):
82+
self.itemList.append(item)
83+
84+
def count(self):
85+
return len(self.itemList)
86+
87+
def itemAt(self, index):
88+
if index >= 0 and index < len(self.itemList):
89+
return self.itemList[index]
90+
91+
return None
92+
93+
def takeAt(self, index):
94+
if index >= 0 and index < len(self.itemList):
95+
return self.itemList.pop(index)
96+
97+
return None
98+
99+
def expandingDirections(self):
100+
return Qt.Orientations(Qt.Orientation(0))
101+
102+
def hasHeightForWidth(self):
103+
return True
104+
105+
def heightForWidth(self, width):
106+
height = self.doLayout(QRect(0, 0, width, 0), True)
107+
return height
108+
109+
def setGeometry(self, rect):
110+
super(FlowLayout, self).setGeometry(rect)
111+
self.doLayout(rect, False)
112+
113+
def sizeHint(self):
114+
return self.minimumSize()
115+
116+
def minimumSize(self):
117+
size = QSize()
118+
119+
for item in self.itemList:
120+
size = size.expandedTo(item.minimumSize())
121+
122+
margin, _, _, _ = self.getContentsMargins()
123+
124+
size += QSize(2 * margin, 2 * margin)
125+
return size
126+
127+
def doLayout(self, rect, testOnly):
128+
x = rect.x()
129+
y = rect.y()
130+
lineHeight = 0
131+
132+
for item in self.itemList:
133+
wid = item.widget()
134+
spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton,
135+
QSizePolicy.PushButton, Qt.Horizontal)
136+
spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton,
137+
QSizePolicy.PushButton, Qt.Vertical)
138+
nextX = x + item.sizeHint().width() + spaceX
139+
if nextX - spaceX > rect.right() and lineHeight > 0:
140+
x = rect.x()
141+
y = y + lineHeight + spaceY
142+
nextX = x + item.sizeHint().width() + spaceX
143+
lineHeight = 0
144+
145+
if not testOnly:
146+
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
147+
148+
x = nextX
149+
lineHeight = max(lineHeight, item.sizeHint().height())
150+
151+
return y + lineHeight - rect.y()
152+
153+
154+
if __name__ == '__main__':
155+
156+
import sys
157+
158+
app = QApplication(sys.argv)
159+
mainWin = Window()
160+
mainWin.show()
161+
sys.exit(app.exec_())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2018年9月25日
6+
@author: Irony
7+
@site: https://pyqt5.com , https://github.com/892768447
8+
@email: 892768447@qq.com
9+
@file: AnimationShadowEffect
10+
@description: 边框动画阴影动画
11+
"""
12+
from PyQt5.QtCore import QPropertyAnimation, pyqtProperty
13+
from PyQt5.QtWidgets import QGraphicsDropShadowEffect
14+
15+
16+
__Author__ = """By: Irony
17+
QQ: 892768447
18+
Email: 892768447@qq.com"""
19+
__Copyright__ = 'Copyright (c) 2018 Irony'
20+
__Version__ = 1.0
21+
22+
23+
class AnimationShadowEffect(QGraphicsDropShadowEffect):
24+
25+
def __init__(self, color, *args, **kwargs):
26+
super(AnimationShadowEffect, self).__init__(*args, **kwargs)
27+
self.setColor(color)
28+
self.setOffset(0, 0)
29+
self.setBlurRadius(0)
30+
self._radius = 0
31+
self.animation = QPropertyAnimation(self)
32+
self.animation.setTargetObject(self)
33+
self.animation.setDuration(2000) # 一次循环时间
34+
self.animation.setLoopCount(-1) # 永久循环
35+
self.animation.setPropertyName(b'radius')
36+
# 插入值
37+
self.animation.setKeyValueAt(0, 1)
38+
self.animation.setKeyValueAt(0.5, 30)
39+
self.animation.setKeyValueAt(1, 1)
40+
41+
def start(self):
42+
self.animation.start()
43+
44+
def stop(self, r=0):
45+
# 停止动画并修改半径值
46+
self.animation.stop()
47+
self.radius = r
48+
49+
@pyqtProperty(int)
50+
def radius(self):
51+
return self._radius
52+
53+
@radius.setter
54+
def radius(self, r):
55+
self._radius = r
56+
self.setBlurRadius(r)

QGraphicsDropShadowEffect/Lib/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)