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. Creating custom animation by altering the size of a widget in loop.
Qt 6.11 is out! See what's new in the release blog

Creating custom animation by altering the size of a widget in loop.

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 3.4k 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by Ahti
    #1

    I am trying to create a custom animation that would keep decreasing or increasing the size of widget in a loop with a custom delay function ( that delays the time for few seconds ) . but somehow its not working here is the code :

    void delay(unsigned int sec){
    
        clock_t goal = sec + clock();
        while (goal > clock());
    }
    
    void RamadanTimes::on_menucontroller_clicked(){
    
        if (menubar->isVisible()){
            for (int limit = 150;limit > 0;limit -= 10){
                menubar->setGeometry(4,71,limit,440);
                menubar->show();
                delay(1000);
            }
            menubar->hide();
        }else{
            for (int limit = 20;limit != 160;limit += 10 ){
                menubar->setGeometry(4,71,limit,440);
                menubar->show();
                delay(1000);
            }
        }
        menubar->setGeometry(4,71,160,440); // original size of menubar 
    }
    

    Thanks.

    what is a signature ?? Lol

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about a QPropertyAnimation ?

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      AhtiA 1 Reply Last reply
      2
      • AhtiA Ahti

        I am trying to create a custom animation that would keep decreasing or increasing the size of widget in a loop with a custom delay function ( that delays the time for few seconds ) . but somehow its not working here is the code :

        void delay(unsigned int sec){
        
            clock_t goal = sec + clock();
            while (goal > clock());
        }
        
        void RamadanTimes::on_menucontroller_clicked(){
        
            if (menubar->isVisible()){
                for (int limit = 150;limit > 0;limit -= 10){
                    menubar->setGeometry(4,71,limit,440);
                    menubar->show();
                    delay(1000);
                }
                menubar->hide();
            }else{
                for (int limit = 20;limit != 160;limit += 10 ){
                    menubar->setGeometry(4,71,limit,440);
                    menubar->show();
                    delay(1000);
                }
            }
            menubar->setGeometry(4,71,160,440); // original size of menubar 
        }
        

        Thanks.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Ahti Well, it cannot work like this: you're blocking the event loop. Do not block the Qt event loop ever!
        Take a look at what @SGaist suggested or use QTimer.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • SGaistS SGaist

          Hi,

          What about a QPropertyAnimation ?

          Hope it helps

          AhtiA Offline
          AhtiA Offline
          Ahti
          wrote on last edited by
          #4

          @SGaist Yeah okay how can i use QPropertyAnimation in my example ?

          what is a signature ?? Lol

          jsulmJ 1 Reply Last reply
          1
          • AhtiA Ahti

            @SGaist Yeah okay how can i use QPropertyAnimation in my example ?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Ahti Did you read the documentation?
            There is an example doing exactly what you want to do:

            QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
            animation->setDuration(10000);
            animation->setStartValue(QRect(0, 0, 100, 30));
            animation->setEndValue(QRect(250, 250, 100, 30));
            
            animation->start();
            

            http://doc.qt.io/qt-5/qpropertyanimation.html

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            AhtiA 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Ahti Did you read the documentation?
              There is an example doing exactly what you want to do:

              QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
              animation->setDuration(10000);
              animation->setStartValue(QRect(0, 0, 100, 30));
              animation->setEndValue(QRect(250, 250, 100, 30));
              
              animation->start();
              

              http://doc.qt.io/qt-5/qpropertyanimation.html

              AhtiA Offline
              AhtiA Offline
              Ahti
              wrote on last edited by Ahti
              #6

              @jsulm yeah i did read the documentation but i quiet didn't get it. okay leave it i will look into it myself that way i would learn alot right ?

              thanks for your help... God bless you brother :)

              what is a signature ?? Lol

              jsulmJ 1 Reply Last reply
              1
              • AhtiA Ahti

                @jsulm yeah i did read the documentation but i quiet didn't get it. okay leave it i will look into it myself that way i would learn alot right ?

                thanks for your help... God bless you brother :)

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Ahti Yes, learning by doing is a good idea :-)

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #8

                  Hi,

                  @Ahti

                  U have marked as solved, if u have any queries while doing , u can again ask in this topic.
                  have a nice day, cheers,

                  Thanks,

                  Pradeep Kumar
                  Qt,QML Developer

                  AhtiA 1 Reply Last reply
                  0
                  • Pradeep KumarP Pradeep Kumar

                    Hi,

                    @Ahti

                    U have marked as solved, if u have any queries while doing , u can again ask in this topic.
                    have a nice day, cheers,

                    Thanks,

                    AhtiA Offline
                    AhtiA Offline
                    Ahti
                    wrote on last edited by
                    #9

                    @Pradeep-Kumar okay brother as you say :D

                    what is a signature ?? Lol

                    1 Reply Last reply
                    1
                    • Pradeep KumarP Offline
                      Pradeep KumarP Offline
                      Pradeep Kumar
                      wrote on last edited by
                      #10

                      @Ahti

                      Happy coding brother.

                      Thanks,

                      Pradeep Kumar
                      Qt,QML Developer

                      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