如何在 PyQt5 中使用 QMovie 应用边框半径或以其他方式实现圆角效果?它似乎对 QSS 没有反应。尽管我不认为它是相关的,但无论如何,这是我当前的代码,以了解我尝试过的内容:
image = QLabel()
image.setObjectName("rant-image")
movie = QMovie("image_cache/" + img_name)
image.setMovie(movie)
movie.start()
与 QSS:
QLabel#rant-image{
border-radius: 5px;
}
我还尝试通过子类化 QWidget 来绘制每个paintEvent 的当前像素图,但没有出现任何内容,并且像素图的尺寸为 0:
invisible_pen = QPen()
invisible_pen.setWidth(0)
invisible_pen.setStyle(Qt.NoPen)
class RoundedMovie(QWidget):
def __init__(self, movie, parent=None):
QWidget.__init__(self, parent)
self.movie = movie
def setMovie(self, movie):
self.movie = movie
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
pixmap = self.movie.currentPixmap()
brush = QBrush(pixmap)
rect = QRect(0, 0, pixmap.width() - 10, pixmap.height() - 10)
painter.setPen(invisible_pen)
painter.setBrush(brush)
painter.drawRoundedRect(rect, 5, 5)
我也知道上面的实现是行不通的,因为paintEvent 的发生频率不足以按预期播放电影