Important: Please read the Qt Code of Conduct -

QPropertyAnimation to Show a Widget(Visibility)

  • Hey,

    Am just looking for a suggestion regarding transitions for Widgets.

    Sorry abt the long post but just a few things to explain.

    Firstly I'm having an Overlay Widget on my mainwindow (a widget that just draws a black rect with alpha around 180 based on the main screen size from its paintEvent)

    This overlay widget also has a child stacked widget which gets positioned on the overlay widget itself.

    Now I'm trying to set a very simple transition from say visibility(through opacity) 0 -> 1 in abt 1000ms and the reverse when hiding it.

    I've tried a few samples from forums and the qt examples for this but im not having much luck.

    1. The Overlaywidget is a child itself so windowOpacity doesnt apply to it. So I guess i'd have to go with the procedure from "Here":

    2. Now to test, I just removed the overlay from being a child and the QProperty seemed fine. However when the opacity is changed via the transition it just disregards the paintEvent's alpha and makes the background rectangle completely black when animation reaches 1. Is there anyway to avoid this. If i set the transition Animation to end at alpha .7 then the stacked widget inside the overlay is also at an overlay of 0.7.

    3. Also I'm in need of a procedure to set the visibility of the overlay widget only by the transition. I'm having to set the overlay visible before starting the animation or nothing appears on my screen and doing so I'm guessing is wrong since it might cause a flicker on a slower machine where the window appears at full opacity and then starts the animation from 0 again.


  • bah soz abt the post. solved it myself (most of)

    QGraphicsOpacityEffect* fade_effect = new QGraphicsOpacityEffect(this);
    QPropertyAnimation *animation = new QPropertyAnimation(fade_effect, "opacity");

    Just the last 2 lines im not toally sure about yet if its ok to use like that. Just dont want to end up with a nasty flicker on some less powerful machine because of it.

Log in to reply