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. Basic animation on QPushbutton
Forum Updated to NodeBB v4.3 + New Features

Basic animation on QPushbutton

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 3.5k 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.
  • M Offline
    M Offline
    Mistrale
    wrote on last edited by Mistrale
    #1

    Hi,

    Im trying to do a basic animation on a clicked qpushbutton to reduce it but nothing happends.

    I have only a a QPushButton design with Qt designer on the MainWindow. Heres the code of the MainWindow :

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <QPropertyAnimation>
    #include <QStateMachine>
    #include <QSignalTransition>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(test()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;

    }

    #include <iostream>

    void MainWindow::test() {
    std::cout << "enter in function : " << std::endl;
    QPropertyAnimation animation(ui->pushButton, "geometry");
    animation.setDuration(10000);
    animation.setStartValue(QRect(ui->pushButton->x(), ui->pushButton->y(),
    ui->pushButton->width(), ui->pushButton->height()));
    animation.setEndValue(QRect(0,0,0,0));

    animation.setEasingCurve(QEasingCurve::OutBounce);
    
    animation.start();
    

    }

    I have tried to put the QPushButton in a Layout but it does the same.

    Does anyone have an idea ?

    Thank you.

    EDIT //

    I set the animation in the mainwindow class and it worked !

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

      Hi and welcome to devnet,

      Since you allocate your animation on the stack it's destroyed at the end of test, so just after the call to start so it doesn't have the time to run.

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mistrale
        wrote on last edited by Mistrale
        #3

        Thanks a lot it works now, but i have a question, how can I reduce a QPushButton without a starting point ? i want the center of the qpushbutton to be the same when resized

        1 Reply Last reply
        0
        • ValentinMicheletV Offline
          ValentinMicheletV Offline
          ValentinMichelet
          wrote on last edited by
          #4

          I could not find any setOrigin method in QPropertyAnimation, so maybe a solution would be to combine two animations: yours and a translation that centres the button at the same speed. You can look at http://doc.qt.io/qt-5/qparallelanimationgroup.html for parallel animations.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mistrale
            wrote on last edited by
            #5

            Yeah the only problem is that i dont get how to make a transition from a position to another

            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