我想将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.发布于 2020-06-18 17:46:47
在将新的QGraphicsOpacityEffect分配给widget或其子组件之前,应按如下所示删除先前为该widget设置的QGraphicsOpacityEffect:
connect(animation,&QPropertyAnimation::finished,[=](){
eff->deleteLater();
});如错误所示:
QPainter::begin:一个绘制设备一次只能由一个绘制者绘制。
有两个或更多的绘制者试图同时绘制小部件。
背景:
QGraphicsEffect是QGraphicsOpacityEffect和Qt中任何图形效果库的基类。如果你查看QGraphicsEffect源代码,你会发现它使用QPainter进行绘图。因此,用户在任何小部件上使用任何图形效果类都意味着他正在启动一个QPainter来渲染效果,很明显,我们不能在设备或表面上一次使用多个QPainter进行绘制。
https://stackoverflow.com/questions/55597230
复制相似问题