tags:

views:

39

answers:

2

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?

A: 

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.

Caleb Huitt - cjhuitt
A: 

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!

Dan-George Filimon
Thank you!Seems, that I should try the second way, cause I need to make my widgets (buttons, text, etc.) smoothly transparent on some event.
Kuzmin Stepan