首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用QPropertyAnimation时QPainter崩溃

使用QPropertyAnimation时QPainter崩溃
EN

Stack Overflow用户
提问于 2019-04-10 00:21:00
回答 1查看 273关注 0票数 1

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

代码语言:javascript
复制
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)

一切正常,但当我将鼠标悬停在标签上时,图像就会消失,并得到如下警告:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2020-06-18 17:46:47

在将新的QGraphicsOpacityEffect分配给widget或其子组件之前,应按如下所示删除先前为该widget设置的QGraphicsOpacityEffect

代码语言:javascript
复制
connect(animation,&QPropertyAnimation::finished,[=](){
           eff->deleteLater();
});

如错误所示:

QPainter::begin:一个绘制设备一次只能由一个绘制者绘制。

有两个或更多的绘制者试图同时绘制小部件。

背景:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55597230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档