我使用QVideoWidget
库的QMediaPlayer
和PyQt5
对象创建了媒体播放器。我正在尝试为视频上的透明对象或图像设置动画,我可以为图像对象设置动画,但它不是透明的。下面,我提供了一个最小的可复制代码:
import PyQt5.QtCore as C
import PyQt5.QtMultimedia as M
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QFrame
from PyQt5 import QtGui
import sys
from PyQt5.QtCore import QAbstractAnimation, QEasingCurve, QPropertyAnimation, QRect
class Player(QMainWindow):
def __init__(self, master=None):
QMainWindow.__init__(self, master)
self.widget = QWidget(self)
self.setCentralWidget(self.widget)
self.setWindowTitle("Media Player")
url= C.QUrl.fromLocalFile("path to video")
content= M.QMediaContent(url)
self.player = M.QMediaPlayer()
self.player.setMedia(content)
video_widget = QVideoWidget()
self.player.setVideoOutput(video_widget)
self.player.play()
vlayout = QVBoxLayout()
vlayout.addWidget(video_widget)
self.widget.setLayout(vlayout)
pixmap = QtGui.QPixmap()
pixmap.load("path to transparent image")
my_label = QLabel(self)
my_label.setPixmap(pixmap)
my_label.setGeometry(300, 250, 100, 100)
my_label.setFrameStyle(QFrame.NoFrame)
my_label.setAttribute(C.Qt.WA_TranslucentBackground)
self.anim = QPropertyAnimation(my_label, b"geometry")
self.anim.setDuration(5000)
self.anim.setStartValue(QRect(self.width() - my_label.height(), self.height() / 2 + my_label.height() /2,
my_label.width(), my_label.height()))
self.anim.setEndValue(QRect(my_label.height(), self.height() / 2 - my_label.height() /2,
my_label.width(), my_label.height()))
self.anim.setEasingCurve(QEasingCurve.InCubic)
self.anim.start(QAbstractAnimation.DeleteWhenStopped)
app=QApplication(sys.argv)
player = Player()
player.resize(640, 480)
player.show()
player.player.stateChanged.connect( app.quit )
app.exec()
有人可以帮我弄清楚如何为视频上的透明对象/图像设置动画吗?