如何解决如何在Python的PyQt5 QPropertyAnimation中添加背景图像动画
我已经为窗口动画完成了以下代码,但是我无法在其中显示背景图像
import sys
from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QVBoxLayout)
from PyQt5.QtCore import QRect,QPropertyAnimation
from PyQt5 import QtCore,QtGui
from pyautogui import size
# GETTING SCREEN RESOLUTION
width,height = size()
class AppDemo(QWidget):
def __init__(self):
super().__init__()
# SETTING WINDOW GEOMETRY FOR ANIMATION
self.baseHeight = 0
self.extendedHeight = height
self.baseWidth = 0
self.extendedWidth = width
self.rect = QRect(0,self.baseWidth,self.baseHeight)
self.setGeometry(self.rect)
# CREATING FRAMELESS WINDOW
flags = QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.setWindowFlags(flags)
self.setStyleSheet("*\n"
"{\n"
"background-image:url(BACKGROUND.jpg);\n"
"}")
self.resizeWindow()
#THE ANIMATION EFFECT
def resizeWindow(self):
currentHeight = self.height()
currentWidth = self.width()
if self.baseHeight == currentHeight and self.width() == currentWidth:
baseHeight = self.baseHeight
baseWidth = self.baseWidth
extendedHeight = self.extendedHeight
extendedWidth = self.extendedWidth
else:
baseHeight = self.extendedHeight
baseWidth = self.extendedWidth
extendedHeight = self.baseHeight
extendedWidth = self.baseWidth
# STARTING ANIMATION
self.animation = QPropertyAnimation(self,b'geometry')
self.animation.setDuration(800)
self.animation.setStartValue(QRect(0,baseWidth,baseHeight))
self.animation.setEndValue(QRect(0,extendedWidth,extendedHeight))
self.animation.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
sys.exit(app.exec_())
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。