如何在 Qt4 中为小部件透明度设置动画?
我需要为小部件透明度设置动画。 在我看来,我应该使用 QPropertyAnimation。但我如何定义小部件半透明呢?我应该使用这样的东西吗?
I need to animate widget transparency.
It seems to me, that I should use QPropertyAnimation. But how could i define widget translucent? Should I use something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少从我玩过的内容来看,您的问题有两个子答案:
不透明度
。不幸的是,这意味着使用代理小部件 QGrapgicsProxyWidget 来保持普通小部件与其图形小部件对应物同步,因为 QGraphicsWidget 不继承 QWidget。要了解更多信息,请查看动画框架示例,特别是有关如何使用代理小部件的状态机。对于 windowOpacity 动画:
QPropertyAnimation animate = new QPropertyAnimation(this, "windowOpacity", this);
animate.setDuration(100);动画.setStartValue(1); animate.setEndValue(0);
animate.start();
这仅适用于支持某种复合扩展的系统。
希望有帮助!
There are two sub-answers to your question, from what I've played with at least:
opacity
. Unfortunately, this means using proxy widgets QGrapgicsProxyWidget to keep normal widgets in sync with their graphics widget counterparts since QGraphicsWidget doesn't inherit QWidget. To find out more, check out the Animation Framework Examples, in particular the State Machine for how to use proxy widgets.For
windowOpacity
animations:QPropertyAnimation animate = new QPropertyAnimation(this, "windowOpacity", this);
animate.setDuration(100); animate.setStartValue(1); animate.setEndValue(0);
animate.start();
This will work only on systems that support some kind of Composite extension.
Hope it helps!
您可以尝试使用
windowOpacity
属性QWidget。如果这不起作用,您可能需要定义自己的属性并在小部件的绘制事件中使用它。You could try using the
windowOpacity
property in QWidget. If that doesn't work, you may need to define your own property and use it in the paint event for your widget.