开发者

How to animate widget transparency in Qt4?

开发者 https://www.devze.com 2023-01-20 09:51 出处:网络
开发者_运维知识库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?There are two

开发者_运维知识库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?


There are two sub-answers to your question, from what I've played with at least:

  1. If you want to set animate the opacity of a QWidget toplevel window, you can use QPropertyAnimation from 0 to 1 on the "windowOpacity" value. You might want to check the exact syntax since I'm using PyQt.
  2. If you want to animate the opacity of a button or of a text label, this property won't work and you need to use QGraphicsWidgets. They inherit QGraphicsItem and so, they have 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消