Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
这个也比较有用

#ifndef UI_TEST_H
#define UI_TEST_H

#include 
<QtCore/QVariant>
#include 
<QtGui/QAction>
#include 
<QtGui/QApplication>
#include 
<QtGui/QButtonGroup>
#include 
<QtGui/QGridLayout>
#include 
<QtGui/QGroupBox>
#include 
<QtGui/QHeaderView>
#include 
<QtGui/QLineEdit>
#include 
<QtGui/QPushButton>
#include 
<QtGui/QTextEdit>
#include 
<QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Form
{
public:
    QGroupBox 
*group2;
    QWidget 
*layoutWidget;
    QGridLayout 
*gridLayout_2;
    QPushButton 
*pushButton;
    QLineEdit 
*lineEdit_11;
    QTextEdit 
*textEdit;
    QPushButton 
*button;
    QGroupBox 
*group1;
    QWidget 
*layoutWidget1;
    QGridLayout 
*gridLayout;
    QLineEdit 
*lineEdit;
    QLineEdit 
*lineEdit_2;
    QLineEdit 
*lineEdit_3;
    QLineEdit 
*lineEdit_5;
    QLineEdit 
*lineEdit_6;
    QLineEdit 
*lineEdit_7;
    QLineEdit 
*lineEdit_4;
    QLineEdit 
*lineEdit_8;
    QLineEdit 
*lineEdit_9;
    QLineEdit 
*lineEdit_10;

    
void setupUi(QWidget *Form)
    {
        
if (Form->objectName().isEmpty())
            Form
->setObjectName(QString::fromUtf8("Form"));
        Form
->resize(315452);
        group2 
= new QGroupBox(Form);
        group2
->setObjectName(QString::fromUtf8("group2"));
        group2
->setGeometry(QRect(10210291231));
        layoutWidget 
= new QWidget(group2);
        layoutWidget
->setObjectName(QString::fromUtf8("layoutWidget"));
        layoutWidget
->setGeometry(QRect(1020271201));
        gridLayout_2 
= new QGridLayout(layoutWidget);
        gridLayout_2
->setObjectName(QString::fromUtf8("gridLayout_2"));
        gridLayout_2
->setContentsMargins(0000);
        pushButton 
= new QPushButton(layoutWidget);
        pushButton
->setObjectName(QString::fromUtf8("pushButton"));

        gridLayout_2
->addWidget(pushButton, 0011);

        lineEdit_11 
= new QLineEdit(layoutWidget);
        lineEdit_11
->setObjectName(QString::fromUtf8("lineEdit_11"));

        gridLayout_2
->addWidget(lineEdit_11, 0111);

        textEdit 
= new QTextEdit(layoutWidget);
        textEdit
->setObjectName(QString::fromUtf8("textEdit"));
        textEdit
->setMinimumSize(QSize(0120));
        textEdit
->setMaximumSize(QSize(16777215120));

        gridLayout_2
->addWidget(textEdit, 1012);

        button 
= new QPushButton(Form);
        button
->setObjectName(QString::fromUtf8("button"));
        button
->setGeometry(QRect(11127523));
        group1 
= new QGroupBox(Form);
        group1
->setObjectName(QString::fromUtf8("group1"));
        group1
->setGeometry(QRect(1141291170));
        layoutWidget1 
= new QWidget(group1);
        layoutWidget1
->setObjectName(QString::fromUtf8("layoutWidget1"));
        layoutWidget1
->setGeometry(QRect(1030271126));
        gridLayout 
= new QGridLayout(layoutWidget1);
        gridLayout
->setObjectName(QString::fromUtf8("gridLayout"));
        gridLayout
->setContentsMargins(0000);
        lineEdit 
= new QLineEdit(layoutWidget1);
        lineEdit
->setObjectName(QString::fromUtf8("lineEdit"));

        gridLayout
->addWidget(lineEdit, 0011);

        lineEdit_2 
= new QLineEdit(layoutWidget1);
        lineEdit_2
->setObjectName(QString::fromUtf8("lineEdit_2"));

        gridLayout
->addWidget(lineEdit_2, 0111);

        lineEdit_3 
= new QLineEdit(layoutWidget1);
        lineEdit_3
->setObjectName(QString::fromUtf8("lineEdit_3"));

        gridLayout
->addWidget(lineEdit_3, 1011);

        lineEdit_5 
= new QLineEdit(layoutWidget1);
        lineEdit_5
->setObjectName(QString::fromUtf8("lineEdit_5"));

        gridLayout
->addWidget(lineEdit_5, 1111);

        lineEdit_6 
= new QLineEdit(layoutWidget1);
        lineEdit_6
->setObjectName(QString::fromUtf8("lineEdit_6"));

        gridLayout
->addWidget(lineEdit_6, 2011);

        lineEdit_7 
= new QLineEdit(layoutWidget1);
        lineEdit_7
->setObjectName(QString::fromUtf8("lineEdit_7"));

        gridLayout
->addWidget(lineEdit_7, 2111);

        lineEdit_4 
= new QLineEdit(layoutWidget1);
        lineEdit_4
->setObjectName(QString::fromUtf8("lineEdit_4"));

        gridLayout
->addWidget(lineEdit_4, 3011);

        lineEdit_8 
= new QLineEdit(layoutWidget1);
        lineEdit_8
->setObjectName(QString::fromUtf8("lineEdit_8"));

        gridLayout
->addWidget(lineEdit_8, 4111);

        lineEdit_9 
= new QLineEdit(layoutWidget1);
        lineEdit_9
->setObjectName(QString::fromUtf8("lineEdit_9"));

        gridLayout
->addWidget(lineEdit_9, 3111);

        lineEdit_10 
= new QLineEdit(layoutWidget1);
        lineEdit_10
->setObjectName(QString::fromUtf8("lineEdit_10"));

        gridLayout
->addWidget(lineEdit_10, 4011);


        retranslateUi(Form);

        QMetaObject::connectSlotsByName(Form);
    } 
// setupUi

    
void retranslateUi(QWidget *Form)
    {
        Form
->setWindowTitle(QApplication::translate("Form""Form"0, QApplication::UnicodeUTF8));
        group2
->setTitle(QApplication::translate("Form""Edit Box"0, QApplication::UnicodeUTF8));
        pushButton
->setText(QApplication::translate("Form""PushButton"0, QApplication::UnicodeUTF8));
        button
->setText(QApplication::translate("Form""Click"0, QApplication::UnicodeUTF8));
        group1
->setTitle(QApplication::translate("Form""What is this?"0, QApplication::UnicodeUTF8));
    } 
// retranslateUi

};

namespace Ui {
    
class Form: public Ui_Form {};
// namespace Ui

QT_END_NAMESPACE

#endif // UI_TEST_H

#ifndef QTEST_H
#define QTEST_H
#include 
<QWidget>
#include 
<QState>
#include 
<QStateMachine>
#include 
"ui_test.h"

class QTest : public QWidget
{
    Q_OBJECT
public:
    QTest(QWidget 
*parent = 0, Qt::WFlags flags = 0);
    
~QTest();
private:
    Ui::Form ui;
    QStateMachine
* machine;
    QState
* state1;
    QState
* state2;
};

#endif

#include <QPropertyAnimation>
#include 
<QSignalTransition>
#include 
"qtest.h"
#include 
<iostream>

QTest::QTest(QWidget 
*parent, Qt::WFlags flags):QWidget(parent, flags)
{   
    machine 
= new QStateMachine(this);
    state1 
= new QState(machine); 
    state2 
= new QState(machine); 
    
    ui.setupUi(
this);
    ui.textEdit
->resize(280,180);
    ui.group1
->resize(300,210);
    ui.group1
->move(10,40);
    ui.group2
->resize(300,0);
    ui.group2
->move(10,40);
    
    resize(
320,280);

    state1
->assignProperty(ui.group1,"geometry",QRect(10,40,300,210));
    state1
->assignProperty(ui.group2,"geometry",QRect(10,260,300,0));

    state2
->assignProperty(ui.group1,"geometry",QRect(10,40,300,0));
    state2
->assignProperty(ui.group2,"geometry",QRect(10,40,300,210));


    QPropertyAnimation
* ani1 = new QPropertyAnimation(ui.group2,"geometry");  
    ani1
->setDuration(1200);    
    ani1
->setEasingCurve(QEasingCurve::Linear); 
    
    QPropertyAnimation
* ani2 = new QPropertyAnimation(ui.group1,"geometry");  
    ani2
->setDuration(1200);    
    ani2
->setEasingCurve(QEasingCurve::Linear); 
    
    QSignalTransition 
*transition1=state1->addTransition(ui.button,SIGNAL(clicked()),state2); 
    transition1
->addAnimation(ani2);
    transition1
->addAnimation(ani1);
    QSignalTransition 
*transition2=state2->addTransition(ui.button,SIGNAL(clicked()),state1);  
    transition2
->addAnimation(ani2);
    transition2
->addAnimation(ani1);
    machine
->setInitialState(state1);
    machine
->start();      
}

QTest::
~QTest()
{
}
要修改为水平动画,可以做以下修改:
    state1->assignProperty(ui.group1,"geometry",QRect(10,40,300,210));
    state1
->assignProperty(ui.group2,"geometry",QRect(310,40,0,210));

    state2
->assignProperty(ui.group1,"geometry",QRect(10,40,0,210));
    state2
->assignProperty(ui.group2,"geometry",QRect(10,40,300,210));
 
posted on 2013-02-23 15:42 ccsdu2009 阅读(1124) 评论(0)  编辑 收藏 引用 所属分类: QT编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理