Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Animate window (top level widget) opacity

Animate window (top level widget) opacity

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Borzh
    wrote on last edited by
    #1

    I am trying to fade in a window. When the program starts, the window is shown as black and animates opacity as required. But I would like window to be shown completely transparent at the start and removing transparency to be shown completely. Here is the code I use:

    QPropertyAnimation* a1 = NULL;
    if (w) { // I checked, it is not null.
        QGraphicsOpacityEffect *eff = (QGraphicsOpacityEffect *)w->graphicsEffect();
        if (!eff) {
            eff = new QGraphicsOpacityEffect(w);
            from->setGraphicsEffect(eff);
        }
        if (dynamic_cast<QMainWindow*>(w))
            a1 = new QPropertyAnimation(eff, "windowOpacity"); // As top level window, uses this one.
        else
            a1 = new QPropertyAnimation(eff, "opacity");
        a1->setDuration(duration);
        a1->setStartValue(0.0);
        a1->setEndValue(1.0);
        a1->setEasingCurve(QEasingCurve::Linear);
        a1->start(QPropertyAnimation::DeleteWhenStopped);
    }
    

    BTW I tried both opacity and windowOpacity and effect is the same.
    Window creation uses this code:

    setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint | Qt::CustomizeWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi , i tried your code (win 7, qt 5.5)

      MainWindow::MainWindow(QWidget* parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow) {
      ui->setupUi(this);
      setWindowOpacity(0.0);
      QPropertyAnimation *a1 = new QPropertyAnimation(this, "windowOpacity"); // As top level window, uses this one.
      a1->setDuration(3000);
      a1->setStartValue(0.0);
      a1->setEndValue(1.0);
      a1->setEasingCurve(QEasingCurve::Linear);
      a1->start(QPropertyAnimation::DeleteWhenStopped);
      }

      and it fade in very smooth.

      So what platform are you on?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shanmugaraja
        wrote on last edited by
        #3

        @mrjj - I tried the same code in Mac platform using Qt 5.12.6. But still it is not working.

        mrjjM 1 Reply Last reply
        0
        • S shanmugaraja

          @mrjj - I tried the same code in Mac platform using Qt 5.12.6. But still it is not working.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @shanmugaraja
          Hi
          This poster sounds like it does work on macOS
          https://forum.qt.io/topic/59453/solved-widget-fade-in-effect-possible/3

          so if not working on macOS, i guess its not supported if code is 100% the same.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved