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.
|
|
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();
}
|
|
|
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();
}
|
, 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();
}
|
This post has been edited 1 times, last edit by "phil83" (Jul 20th 2011, 8:07am)