Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMainWindow (top level window) is not animating with QPropertyAnimation



  • In my app, I have created the main window by deriving QMainWindowand that window will be displayed after some time later with animation. I am trying to implement the opacity animation for that window using QPropertyAnimation and ```
    QGraphicsOpacityEffect

    
    mainwindow.hpp
    
    

    class MainWindow : public QMainWindow
    {
    QBasicTimer *display_timer;
    void show_overlay_with_delay(void);

    };

    mainwindow.cpp
    
    

    MainWindow::MainWindow(QWidget *parent)
    : ui(new Ui::MainWindow)
    {
    setWindowOpacity(0.0);

    display_timer = new QBasicTimer();
    display_timer->start(5000, this);
    

    }

    void MainWindow::timerEvent(QTimerEvent *event)
    {
    if (this->display_timer->timerId() == event->timerId()) {
    this->show_overlay();
    }
    }

    void MainWindow::show_overlay(void)
    {
        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
        this->setGraphicsEffect(eff);
        QPropertyAnimation *animation = new QPropertyAnimation(eff,"opacity");
        animation->setDuration(5000);
        animation->setStartValue(0);
        animation->setEndValue(1);
        animation->setEasingCurve(QEasingCurve::InBack);
        animation->start(QPropertyAnimation::DeleteWhenStopped);
    }
    
    
    But the window is not animating and also not displayed. I tried it by changing the attributes as opacity and also windowOpacity attributes. But now luck.
    
    I am trying this Mac platform. But it should be working in Windows platform as per the answer on [Qt Topic.](https://forum.qt.io/topic/60977/animate-window-top-level-widget-opacity/2)
    
    Is there any other way, Can we animate the window (top-level) with opacity animation?

  • Lifetime Qt Champion

    Hi
    QEasingCurve::InBack seems not to work (didnt look into why)
    and im not sure QGraphicsOpacityEffect can work on a top level widget aka
    a window.
    Same code applied to a widget in a form works.
    alt text

    Also does
    setWindowOpacity(xxx); work on macOS. ?
    that is other kind of transparency than QGraphicsOpacityEffect provides.
    (impl. details may vary pr platform.)

    Please note "windowOpacity" versus"opacity" for 2 codes.


Log in to reply