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. Qt 5 Frameless Window Opacity Animation problem.
Forum Updated to NodeBB v4.3 + New Features

Qt 5 Frameless Window Opacity Animation problem.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 6.6k 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.
  • Z Offline
    Z Offline
    Zades
    wrote on last edited by
    #1

    With Qt5, a frameless window with opacity animation turns black at the end of animation.
    To make it refresh/update, you need to move your mouse over buttons.
    This issue only happens with Qt5.

    Is this something I can workaround or bug?

    @
    #include <QApplication>
    #include <QPushButton>
    #include <QHBoxLayout>
    #include <QPropertyAnimation>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    // Create transparent popup window.
    QWidget* popup = new QWidget(NULL, Qt::WindowFlags(Qt::FramelessWindowHint | Qt::ToolTip));
    popup->setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
    popup->setAttribute(Qt::WA_TranslucentBackground);

    // Add button to popup window.
    QHBoxLayout* layout = new QHBoxLayout(popup);
    QPushButton* button1 = new QPushButton(popup);
    button1->setFixedSize(200, 300);
    layout->addWidget(button1);
    QPushButton* button2 = new QPushButton(popup);
    button2->setFixedSize(200, 300);
    layout->addWidget(button2);

    // Create opacity animation.
    QPropertyAnimation* fadeInAnimation = new QPropertyAnimation(popup, "windowOpacity");
    fadeInAnimation->setDuration(1000);
    fadeInAnimation->setStartValue(0.0);
    fadeInAnimation->setEndValue(1.0);

    // Show popup
    popup->setWindowOpacity(0.0);
    fadeInAnimation->start();
    popup->show();

    return a.exec();
    }
    @
    !https://bugreports.qt-project.org/secure/attachment/30717/screenshot-1.jpg!

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      As a somewhat crude workaround you might use this:
      @
      a.connect(fadeInAnimation, SIGNAL(finished()), popup, SLOT(repaint()));
      @

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zades
        wrote on last edited by
        #3

        Thank you for the workaround. It works well with black issue.
        However, it didn't solve a flicker when the window initially shows up. I forgot to mention that.

        UPDATE: I tried to add following code right before show(), this seems to fix initial flicker issue.
        @
        popup->repaint();
        popup->show();
        @

        Btw, if you create same popup repeatedly, you'll see black rectangle time to time even with workarounds.

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I'd say don't start the animation before you show the window ie. change this:
          @
          fadeInAnimation->start();
          popup->show();
          @
          to that:
          @
          popup->show();
          fadeInAnimation->start();
          @

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zades
            wrote on last edited by
            #5

            I am still seeing black rectangle between popups.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jassim92
              wrote on last edited by
              #6

              you must be using windows 8 which doesnt supports the opengl - or the transparent windows thing

              1 Reply Last reply
              0
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                jassim92- of course Windows 8 supports OpenGL and layered composition.
                OP actually solved his problem (to an extent) so what are you basing that claim on and what OpenGL has to do with it?

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  even uglier but working: ;)
                  @
                  QObject::connect( fadeInAnimation, SIGNAL(valueChanged(QVariant)), popup, SLOT(repaint()) );
                  @

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  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