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. Animation doesn't work outside constructor

Animation doesn't work outside constructor

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.3k 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.
  • L Offline
    L Offline
    LucianoDE
    wrote on last edited by
    #1

    Hi, I'm using Qt creator 2.4.1 (4.8.0 library) under linux. I successfully developed a Widget based in a QDialog in which a fancy animation (Qframe geometry property) runs properly. Then the problem came up when I included this widget into another one. The animation no longer works. I found out that if I include it inside the constructor of the second widget, the animation works again, but when I executed outside, doesn't. I tried creating the Dialog widget as a pointer, as a local variable, as a global variable, as a private member in the second class, but nothing works. No mater if I initialise the class pointer in the constructor of the second widget, as long as I don't executed in that place, the animation doesn't work.
    Could anyone offer me a helping hand.
    Many thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akonradwesolutions
      wrote on last edited by
      #2

      Did you add your animated widget to a layout in the parent widget? If so this will certainly stop your geometry animation from working, since the layout will try to manage the widget geometry. If this is not the case you should post a few lines of code that can help us analyze your problem.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LucianoDE
        wrote on last edited by
        #3

        Part of the source code in configuration dialog "MyClass" constructor is
        @
        MyDialog::MyDialog( QWidget *parent) : QDialog(parent, Qt::FramelessWindowHint ),
        ui(new Ui::MyDialog)
        {
        ui->setupUi(this);
        QPropertyAnimation *animation = new QPropertyAnimation( ui->pushButton, "geometry", this );
        animation->setDuration(500);
        animation->setEasingCurve( QEasingCurve::InOutQuad );

        QStateMachine *stateMachine = new QStateMachine(this);
        QState *state1 = new QState(stateMachine);
        QState *state2 = new QState(stateMachine);

        state1->assignProperty( ui->pushButton, "geometry", QRect( 60, 125, 680, 220));
        state2->assignProperty( ui->pushButton, "geometry", QRect( 60, 50, 680, 220 ));

        QSignalTransition *goState2Transition = new QSignalTransition(ui->nextButton, SIGNAL(clicked()), state1);
        QSignalTransition *goState1Transition = new QSignalTransition(ui->backButton, SIGNAL(clicked()), state2);
        goState2Transition->setTargetState( state2 );
        goState2Transition->addAnimation( animation );
        goState1Transition->setTargetState( state1 );
        goState1Transition->addAnimation( animation );
        stateMachine->setInitialState( state1 );
        stateMachine->start();
        }@

        When I run the configuration dialog from other project, let's call it MainProject, as long as I included in the constructor of that other project, works fine. I tried to show MyDialog from a function inside my MainProject and the animation doesn't work.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          akonradwesolutions
          wrote on last edited by
          #4

          Can you show code samples that illustrate the use of your class that breaks your animation and the use case that works?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LucianoDE
            wrote on last edited by
            #5

            The use is simple. When I call MyDialog from MainProject constructor, works
            @MainProject::MainProject(QWidget parent = 0) : QDialog(parent)
            {
            ui->setupUi(this);

            ..
            MyDialog * myDialog= new MyDialog(this);
            myDialog->exec();
            ..
            ..
            }
            @
            now when I call from another function by copying exactly the same piece of code, doesn't work.
            Now the funny thing I found out, is that if I delete the whole object files and make a clean an rebuild all, the animation works, but only the first time. After that, anytime I re-run the application, doesn’t work anymore.

            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