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. [SOLVED] Widget Fade In Effect Possible?

[SOLVED] Widget Fade In Effect Possible?

Scheduled Pinned Locked Moved General and Desktop
qt5.5widgetfadeeffect
5 Posts 3 Posters 7.2k Views
  • 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.
  • M Offline
    M Offline
    maximo
    wrote on 6 Oct 2015, 07:06 last edited by maximo 10 Jul 2015, 06:06
    #1

    Is it possible to have a widget fade-in effect? I'm using Qt 5.5 Open Source.

    Currently I'm doing inline dialogs in my application. So, instead of showing a separate window (complete with titlebar, etc.), I'm showing a promoted widget. So, I dim the background using an opaque QFrame control, and then inside that show a QStackedWidget control where I have each of my dialogs like "Are you sure?" and "Register Product" and "Help & Support Info".

    To make this even snazzier, I want to know if I can fade in the widget and its contents somehow. Is there an easy way to do that, such as a stylesheet transition?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Oct 2015, 07:53 last edited by mrjj 10 Jun 2015, 07:54
      #2

      Hi
      well if you are on windows, you could use the windowOpacity
      see here for some code
      http://www.qtcentre.org/threads/56737-Implementing-fade-in-fade-out-for-a-modal-QDialog

      He uses QPropertyAnimation to animate the property.

      M 1 Reply Last reply 6 Oct 2015, 20:25
      1
      • M mrjj
        6 Oct 2015, 07:53

        Hi
        well if you are on windows, you could use the windowOpacity
        see here for some code
        http://www.qtcentre.org/threads/56737-Implementing-fade-in-fade-out-for-a-modal-QDialog

        He uses QPropertyAnimation to animate the property.

        M Offline
        M Offline
        maximo
        wrote on 6 Oct 2015, 20:25 last edited by
        #3

        @mrjj I found that your technique works on a Mac as well. (I'm running El Captain version of OSX.)

        QPropertyAnimation *a = new QPropertyAnimation(this,"windowOpacity");
        a->setDuration( 150 );
        a->setStartValue( 0.0 );
        a->setEndValue( 1.0 );
        a->start();
        

        That works great on a window. If I want to do it on a widget, one technique I found was to just change it's geometry properties like so:

        // w is my widget
        QRect r = QRect();
        r.setX(w->x());
        r.setY(w->y());
        r.setHeight(w->height());
        r.setWidth(w->width());
        QRect r2 = r;
        r2.setX(w->x() + (w->width() / 2));
        r2.setY(w->y() + (w->height() / 2));
        r2.setHeight(0);
        r2.setWidth(0);
        QPropertyAnimation *a = new QPropertyAnimation(w,"geometry");
        a->setDuration( 150 );
        a->setStartValue( r2 );
        a->setEndValue( r );
        a->start();
        

        Then, reverse this animation on hiding the widget.

        1 Reply Last reply
        1
        • L Offline
          L Offline
          LuGRU
          wrote on 7 Oct 2015, 03:41 last edited by
          #4

          Alternative approach, use QGraphicsOpacityEffect and animate opacity of QGraphicsOpacityEffect.

          M 1 Reply Last reply 7 Oct 2015, 05:59
          2
          • L LuGRU
            7 Oct 2015, 03:41

            Alternative approach, use QGraphicsOpacityEffect and animate opacity of QGraphicsOpacityEffect.

            M Offline
            M Offline
            maximo
            wrote on 7 Oct 2015, 05:59 last edited by
            #5

            @LuGRU Very cool! I finally was able to pull this off with my promoted widget, whereas other techniques didn't work unless I switched the effect to width/height animation.

            // w is my widget
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            w->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->start(QPropertyAnimation::DeleteWhenStopped);
            
            1 Reply Last reply
            0

            1/5

            6 Oct 2015, 07:06

            • Login

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