1

我想将 propertyAnimation 中的 graphicsOpacityEffect 用于包含带有像素图的标签的 QFrame。我的代码是:

eff = QGraphicsOpacityEffect(frame)
widget.setGraphicsEffect(eff)            

animation = QPropertyAnimation(eff, b"opacity")
animation.setStartValue(0)
animation.setEndValue(1)
animation.setDuration(500)
animation.setEasingCurve(QEasingCurve.InBack)
animation.start(QPropertyAnimation.DeleteWhenStopped)

一切正常,但是当我将标签悬停时,图像消失,我收到如下警告:

QPainter::setWorldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::translate: Painter not active
QPainter::worldTransform: Painter not active
QWidgetEffectSourcePrivate::pixmap: Painter not active
QPainter::worldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
4

1 回答 1

0

在将新的QGraphicsOpacityEffect分配给小部件或其子级之前,您应该删除先前设置的QGraphicsOpacityEffect到小部件,如下所示:

connect(animation,&QPropertyAnimation::finished,[=](){
           eff->deleteLater();
});

正如错误所说:

QPainter::begin:一个绘画设备一次只能由一个画家绘画。

有两个或多个画家试图同时绘制小部件。

背景:

QGraphicsEffect是 QGraphicsOpacityEffect 的基类,适用于 Qt 中的任何图形效果库。如果您查看QGraphicsEffect源,它使用 QPainter 进行绘图。因此,用户在任何小部件上使用任何图形效果类都意味着他正在启动一个QPainter来渲染效果,很明显我们不能在设备或表面上一次使用多个QPainter进行绘制。

于 2020-06-18T09:46:46.760 回答