/
window_border_animation.py
47 lines (37 loc) · 1.35 KB
/
window_border_animation.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
import sys
from PySide2.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget
from PySide2.QtCore import Qt, QPropertyAnimation, Property
from PySide2.QtGui import QColor, QPalette
class MainWindow(QMainWindow):
""" just a trick to create animation for border """
def __init__(self):
QMainWindow.__init__(self)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(300,300)
layout = QVBoxLayout()
label = QLabel()
label.setFixedSize(280,280)
layout.addWidget(label, alignment=Qt.AlignCenter)
self.setStyleSheet("QLabel{background-color:white}")
self.blink_animation = QPropertyAnimation(self, b"backcolor")
self.blink_animation.setStartValue(QColor(255,0,0))
self.blink_animation.setKeyValueAt(0.5, QColor(0,0,255))
self.blink_animation.setEndValue(QColor(255,0,0))
self.blink_animation.setDuration(3000)
#self.blink_animation.setLoopCount(-1)
self.blink_animation.start()
container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)
def getBackColor(self):
return self.palette().color(QPalette.Window)
def setBackColor(self, color):
pal = self.palette()
pal.setColor(QPalette.Window, color)
self.setPalette(pal)
backcolor = Property(QColor, getBackColor, setBackColor)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()