You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Seth90

Beginner

  • "Seth90" is male
  • "Seth90" started this thread

Posts: 5

Location: Italy

Occupation: Informatics Science Student @ University of Padua

  • Send private message

1

Saturday, July 16th 2011, 10:34am

flickering in frame moving animation

Hi guys,

i try to do this simple animation:







the layout of window is grid (for window autoresize).

the first animation where frame 1 go out run correctly, but the second animation where frame 2 go inside the window not run correctly... the animation flicker...

this is the code:
[where:
Button 1=ButtonLogin;
Frame 1= login;
frame 2= linkedin;]




Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//QWidget_home.cpp

Home::Home(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Home)
{
    ui->setupUi(this);
    inizio();
}

void Home::inizio()
    {
            databaseOn(); //read data from sql Database
            hideall();
            ui->Login->show(); //show the frame 1

            //set the image and labels in all frame
            QPixmap immagine(":/immagine1.jpg");
            ui->labelimage->setPixmap(immagine);
            QPixmap immaginelogin(":/loginlogo.png");
            ui->labelloginimage->setPixmap(immaginelogin);
            ui->linePassword->setEchoMode(QLineEdit::Password);
            QPixmap immaginewelcome(":/welcome.png");
            ui->labelWelcome->setPixmap(immaginewelcome);
   }

void Home::hideall(){ //hide all 
    ui->Login->hide();
    ui->Linkedin->hide();
    ui->ModificaProfilo->hide();
}

//[...]

void Home::on_pushButtonLogin_clicked()
{

    //convert data in form for the database (is a vector)
    bool logged=true;
    QString * s= new QString[2];
    s[0]=ui->lineUsername->text();
    s[1]=ui->linePassword->text();
    try{
        cercami(s);
    }catch (errori){
        ui->lineUsername->clear();
        ui->linePassword->clear();
        logged=false;
    }
    //try to read data from vector

    try {
        scriviProfilo(logged); //try to complete the label of frame linkedin with database information
    } catch (errori) {}

    //show frame 2
    showLinkedin();

}

//[...]

void Home::showLinkedin() { //hide the frame1


    int dimensioneLarghezza=geometry().width()-24;
    int dimensioneAltezza=geometry().height()-24;
    int dimensioneX=12;//ui->Login->geometry().x();
    int dimensioneY=12;//ui->Login->geometry().y();
    int surplus=geometry().width()-24;

    QPropertyAnimation *animation = new QPropertyAnimation(ui->Login, "geometry");
    animation->setDuration(500);
    animation->setStartValue(QRect(dimensioneX,dimensioneY,dimensioneLarghezza ,dimensioneAltezza ));
    animation->setEndValue(QRect(-(dimensioneX+surplus),dimensioneY, dimensioneLarghezza ,dimensioneAltezza));
    animation->setEasingCurve(QEasingCurve::InOutExpo);
    animation->start(QAbstractAnimation::DeleteWhenStopped);
    connect(animation, SIGNAL(finished()), SLOT(hideLoginAnimationEnd())); //when is hide show frame 2
}

void Home::hideLoginAnimationEnd(){ //show frame 2
    ui->Login->hide();

    ui->Linkedin->show();

    qDebug()<<geometry().width();
    qDebug()<<geometry().height();
    int dimensioneLarghezza=geometry().width()-24;
    int dimensioneAltezza=geometry().height()-24;
    int dimensioneX=12;
    int dimensioneY=12;
    int surplus=geometry().width()-24;



    QPropertyAnimation *animation = new QPropertyAnimation(ui->Linkedin, "geometry");
    animation->setDuration(500);
    animation->setStartValue(QRect(dimensioneX+surplus,dimensioneY, dimensioneLarghezza, dimensioneAltezza));
    animation->setEndValue(QRect(dimensioneX,dimensioneY, dimensioneLarghezza, dimensioneAltezza));
    animation->setEasingCurve(QEasingCurve::InOutExpo);
    animation->start();
}

someone can help me?

Thanks.

2

Tuesday, July 19th 2011, 10:38am

Hi
I advise you to use QStateMachine in couple with QPropertyAnimation.
All you need is to specify positions of you forms for each state ,add animation to each transition ,conditions for transitons and start the state machine.
This may sounds bit complicated but in code it looks quite clearly

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
TestWidget::TestWidget(QWidget *parent) :
             QWidget(parent){
    /*
        Here we setup ui ..
        Forexample we have two forms and can get it in next manner ui.form1 ui.form2
    */
    //states are declared in testwidget.h
        state1 = new QState();
        state2 = new QState();

    //specify positions for each form in two states . we asume that our forms have width  280 pixels
    //in first state we have to see form1 on the screen so..
        state1->assignProperty(&ui.form1,"pos",QPointF(0,0));
        state1->assignProperty(&ui.form2,"pos",QPointF(280,0));
     //in second state we see form2 on the screen
        state2->assignProperty(&ui.form1,"pos",QPointF(-280,0));
        state2->assignProperty(&ui.form2,"pos",QPointF(0,0));

      //specify transition and condition for it .We assume transtion will be on button clicked signal
        QAbstractTransition *transition = state1->addTransition(ui.form1.button,SIGNAL(clicked()),state2);
      //specify animations for this transition..
        QPropertyAnimation *an1 = new QPropertyAnimation(&ui.form1,"pos",this);
        QPropertyAnimation *an2 = new QPropertyAnimation(&ui.form2,"pos",this);

       //we can specify an easing curve foreach animation
        an1->setEasingCurve(QEasingCurve::InCubic);
        an2->setEasingCurve(QEasingCurve::InQuad);
        //adding animations to transition
        transition1->addAnimation(an1);
        transition1->addAnimation(an2);

        //adding states to the state machine . State machine declared in .h file as variable.
        machine.addState(state1);
        machine.addState(state2);
        machine.setInitialState(state1);

        machine.start();

}


for more information look examples/animation/states

Good Luck!

Seth90

Beginner

  • "Seth90" is male
  • "Seth90" started this thread

Posts: 5

Location: Italy

Occupation: Informatics Science Student @ University of Padua

  • Send private message

3

Tuesday, July 19th 2011, 2:54pm

hi,
thank you phil83 :) , i try to do this function using your code.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void slideInOut(QWidget* obj1,QWidget* obj2){

    QStateMachine machine;


        //states are declared in testwidget.h
            QState *state1 = new QState();
            QState *state2 = new QState();

        //specify positions for each form in two states . we asume that our forms have width  280 pixels
        //in first state we have to see form1 on the screen so..
            state1->assignProperty(obj1,"pos",QPointF(obj1->geometry().x() ,obj1->geometry().y()));
            state1->assignProperty(obj2,"pos",QPointF(1000,obj2->geometry().y()));
         //in second state we see form2 on the screen
            state2->assignProperty(obj1,"pos",QPointF(-1000,obj1->geometry().y()));
            state2->assignProperty(obj2,"pos",QPointF(obj2->geometry().x() ,obj2->geometry().y()));

          //specify transition and condition for it .We assume transtion will be on button clicked signal
            //QAbstractTransition *transition = state1->addTransition(ui.form1.button,SIGNAL(clicked()),state2);
          //specify animations for this transition..
            QPropertyAnimation *an1 = new QPropertyAnimation(obj1,"pos");
            QPropertyAnimation *an2 = new QPropertyAnimation(obj2,"pos");

           //we can specify an easing curve foreach animation
            an1->setEasingCurve(QEasingCurve::InCubic);
            an2->setEasingCurve(QEasingCurve::InQuad);
            an1->setDuration(500);
            an2->setDuration(500);

            //adding states to the state machine . State machine declared in .h file as variable.
            machine.addState(state1);
            machine.addState(state2);
            machine.setInitialState(state1);
            machine.start();
}


but on compiling give me these error:
:-1: error: symbol(s) not found for architecture x86_64
:-1: error: collect2: ld returned 1 exit status

without the function slideInOut all compile correctly, and the program run..

do you know why?

4

Tuesday, July 19th 2011, 10:00pm

Hi .
The code above just for explanation how to deal with state machine ,states and animation. So you can't compile without errors.
I have attached simple project which should compile and work. In it 3 forms move with animation when button 1 on keyboard presses
I think it should help you
phil83 has attached the following file:
  • callwindow.zip (15.91 kB - 7 times downloaded - latest: Jul 18th 2012, 8:24am)

This post has been edited 1 times, last edit by "phil83" (Jul 20th 2011, 8:07am)


Seth90

Beginner

  • "Seth90" is male
  • "Seth90" started this thread

Posts: 5

Location: Italy

Occupation: Informatics Science Student @ University of Padua

  • Send private message

5

Tuesday, July 26th 2011, 9:05am

Thank you so much :D

Similar threads

Used tags

animation, flickering, frame