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 window adds zoom animation for the first time the window will flicker
Forum Updated to NodeBB v4.3 + New Features

Qt window adds zoom animation for the first time the window will flicker

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 795 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.
  • N Offline
    N Offline
    Nan Feng
    wrote on last edited by
    #1

    Hi, I use QPropertyAnimation to act on the geometry property of Form A. When I start the animation through the button in Form B, Form A will flicker for the first time when it starts animating, and then start multiple animations again. It won’t flicker, why is that?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      When you restart the animations, is the formA then in exact same position/size as before?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nan Feng
        wrote on last edited by
        #3

        Hi, I am very happy to get your reply. The position of form A is calculated relative to the position of the parent form and always appears in the upper left corner of the parent form. What I am changing through animation is the width of form A.
        In order not to delay your precious time and solve the problem quickly, I recorded a 30-second video to explain my problem quickly (video link: http://qxgtityw1.hn-bkt.clouddn.com/demo.mp4 ), in the video, the program starts to trigger the animation through an event, the form A (green background) will flash once, and then the animation is all normal after multiple startups, even if the position of the form B is moved, it is still normal, but I don’t understand that the song flashes once What is the situation? When I tested it, there was a very small probability that this would not happen.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Super with video. 😋
          It looks like it's briefly shown with another size before the animation starts and sets the size for the first "key".
          Do you set an initial very small size for it like
          resize(0,0);

          I think this effect comes from the fact that final size calculations are postponed to when it's shown.

          so I assume you call show() and that animation->start()

          and I think in that brief moment we see the sliding window with a bigger size than
          it will get from PropAnim's first value. Then after that its all aligned and show as expected.

          Ps. that App looks awesome.

          1 Reply Last reply
          1
          • N Offline
            N Offline
            Nan Feng
            wrote on last edited by Nan Feng
            #5

            Hi, my code is as follows
            In the constructor of the parent form:

             _jrsSetting = new JRSSetting(); // The window with green background in the video, the default size is 250x545
             _jrsSettingAniSize = new QPropertyAnimation(_jrsSetting, "geometry", this); // the animation of the form
            

            Animation start code:

                 _jrsSetting->move(x(), y()); // Move the green background form to the upper left corner of the parent form
                 _jrsSettingAniSize->setStartValue(QRect(x(), y(), 0, 545));
                 _jrsSettingAniSize->setEndValue(QRect(x(), y(), 250, 545));
                 _jrsSettingAniSize->setDuration(500);
                 _jrsSettingAniSize->setEasingCurve(QEasingCurve::InOutExpo);
                 _jrsSettingAniSize->start();
            
                 _jrsSetting->show();
            

            Still no solution, hell. . . .

            mrjjM 1 Reply Last reply
            0
            • N Nan Feng

              Hi, my code is as follows
              In the constructor of the parent form:

               _jrsSetting = new JRSSetting(); // The window with green background in the video, the default size is 250x545
               _jrsSettingAniSize = new QPropertyAnimation(_jrsSetting, "geometry", this); // the animation of the form
              

              Animation start code:

                   _jrsSetting->move(x(), y()); // Move the green background form to the upper left corner of the parent form
                   _jrsSettingAniSize->setStartValue(QRect(x(), y(), 0, 545));
                   _jrsSettingAniSize->setEndValue(QRect(x(), y(), 250, 545));
                   _jrsSettingAniSize->setDuration(500);
                   _jrsSettingAniSize->setEasingCurve(QEasingCurve::InOutExpo);
                   _jrsSettingAniSize->start();
              
                   _jrsSetting->show();
              

              Still no solution, hell. . . .

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

              @Nan-Feng
              Hi
              try to insert
              jrsSetting->move(x(), y()); // Move the green background form to the upper left corner of the parent form
              jrsSetting->resize(0,0); // new.. set init size to zero to sync with anim start value
              ....

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nan Feng
                wrote on last edited by
                #7

                Hi, the charming me has appeared again. The animation thing uses resize(0, 0); it will still flicker. Put this aside, I will study it carefully when I have time. Now there is another question, I am also drunk. When setting the style sheet of the control, using the constructor's setStyleSheet(); unexpectedly some controls do not take effect, and the method of using a single control setting does not take effect (ui->btn01->setStyleSheet();), but in the .ui file Right-clicking a certain control in the designer to set the style sheet does not have this problem. What may be the reason for this phenomenon?

                mrjjM J.HilkJ 2 Replies Last reply
                0
                • N Nan Feng

                  Hi, the charming me has appeared again. The animation thing uses resize(0, 0); it will still flicker. Put this aside, I will study it carefully when I have time. Now there is another question, I am also drunk. When setting the style sheet of the control, using the constructor's setStyleSheet(); unexpectedly some controls do not take effect, and the method of using a single control setting does not take effect (ui->btn01->setStyleSheet();), but in the .ui file Right-clicking a certain control in the designer to set the style sheet does not have this problem. What may be the reason for this phenomenon?

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

                  @Nan-Feng
                  Hi.
                  Well programming when drunk is always fun :)

                  It normally just work regardless how you call setStyleSheet() but sheets are cascading, meaning it will affects the children also so
                  it can be another stylesheet on the button's parent that interfere.

                  However, from experience I have learn the best way to have a global stylesheet is to assign it to the Qapplication via
                  https://doc.qt.io/qt-5/qapplication.html#styleSheet-prop
                  as it then applies to all windows and widgets.

                  With a global stylesheet make sure you flag all Qss with class type to avoid overlap/clashes

                  Like

                  QPushButton { <<<< tell its for PushButton
                  order: 2px solid #8f8f91;
                      border-radius: 6px;
                      background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                                        stop: 0 #f6f7fa, stop: 1 #dadbde);
                      min-width: 80px;
                  }
                  
                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nan Feng
                    wrote on last edited by
                    #9

                    Hi, I probably found the reason for the flickering problem. The first reason is that it is affected by the style sheet (this I am blinded, what does this have to do with the style sheet...). There is also a second reason that this problem will also occur when the animation is started indirectly by receiving the signal (still under test). I recorded a short video to explain to you (video address: http://qxgtityw1.hn-bkt.clouddn.com/anidemo.mp4).
                    You can see that there is a button on the main program window, the background color is set to red in the constructor, but it is in a commented state.

                    1. When I start the program and click the button to start the animation, the first time there is no flicker, the second time it flickers, and the flicker is not used many times afterwards.

                    2. Cancel the red background style annotation of the button, start the program, click the button to start the animation, only once there is no flicker, and all the remaining tests flicker.

                    What's the situation with this?

                    mrjjM 1 Reply Last reply
                    0
                    • N Nan Feng

                      Hi, I probably found the reason for the flickering problem. The first reason is that it is affected by the style sheet (this I am blinded, what does this have to do with the style sheet...). There is also a second reason that this problem will also occur when the animation is started indirectly by receiving the signal (still under test). I recorded a short video to explain to you (video address: http://qxgtityw1.hn-bkt.clouddn.com/anidemo.mp4).
                      You can see that there is a button on the main program window, the background color is set to red in the constructor, but it is in a commented state.

                      1. When I start the program and click the button to start the animation, the first time there is no flicker, the second time it flickers, and the flicker is not used many times afterwards.

                      2. Cancel the red background style annotation of the button, start the program, click the button to start the animation, only once there is no flicker, and all the remaining tests flicker.

                      What's the situation with this?

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

                      @Nan-Feng
                      Hi
                      I also did play around with it.
                      I still think it's just a bit random and we for a split second see the sliding form in its initial size and then
                      the animations control it.
                      In any case, this is why QML is good at animations and QWidgets not si much:)

                      1 Reply Last reply
                      0
                      • N Nan Feng

                        Hi, the charming me has appeared again. The animation thing uses resize(0, 0); it will still flicker. Put this aside, I will study it carefully when I have time. Now there is another question, I am also drunk. When setting the style sheet of the control, using the constructor's setStyleSheet(); unexpectedly some controls do not take effect, and the method of using a single control setting does not take effect (ui->btn01->setStyleSheet();), but in the .ui file Right-clicking a certain control in the designer to set the style sheet does not have this problem. What may be the reason for this phenomenon?

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #11

                        @Nan-Feng said in Qt window adds zoom animation for the first time the window will flicker:

                        What may be the reason for this phenomenon?

                        what version of Qt do you use? there was a bug, that when a stylesheet was set via Designer and changed via code at runtime, that changes were not applied correctly. :(

                        To the flickering problem, have you tried, moving it way off screen ? ( a million pixels away e.g) show() it, and then moving it into position ?

                        I remember a workaround, where I did it that way.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        1

                        • Login

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