Animation in Label[SOLVED]



  • I want do a animation for one label up. I use Qanimation but i have some problems when the text is to grow.



  • This is not an explanation of your problem. No details, no answer.



  • @void Principal::up()
    {
    QDesktopWidget *desktop = new QDesktopWidget();
    QPropertyAnimation *animation = new QPropertyAnimation(ui->lbTexto, "geometry");
    animation->setDuration(18000);
    animation->setStartValue(QRect(0, this->height(), this->width(), ui->lbTexto->height()));
    animation->setEndValue(QRect(0, 0 - centralWidget()->height(), this->width(), ui->lbTexto->height()));
    animation->setEasingCurve(QEasingCurve::Linear);
    animation->setLoopCount(1);
    connect(animation,SIGNAL(finished()),this,SLOT(down()));
    animation->start();

    }

    void Principal::down()
    {
    QPropertyAnimation *animation = new QPropertyAnimation(ui->lbTexto, "geometry");
    animation->setDuration(10);
    animation->setStartValue(QRect(0, 0, this->width(), ui->lbTexto->height()));
    animation->setEndValue(QRect(0, this->height(), this->width(), ui->lbTexto->height()));
    animation->setLoopCount(1);
    connect(animation,SIGNAL(finished()),this,SLOT(up()));
    animation->start();
    }@

    i want something like "marquee" in HTML. But that do not work.



  • Can you tell us what is not working?
    Compile problem, runtime problem, visual problem, ....

    I can give at least this advise. Create a member QPropertyAnimation mAnimation;
    Initialize it in the constructor once.
    Use then the memberfunction mAnimation->setDirection() to set the animation direction to move it up or down.

    You also created an endless loop between up and down

    in the down function
    animation->setDuration(10);
    The animation is set to 10ms. I would suggest 1000 or the same value as up().

    setLoopCount(1); is not necessary to call because by default it is 1.



  • i have visual problems, because i can not do a flux to up and down, with the time they go upper then the first time.



  • Here I wrote you a 5min solution for you. It is not running that smoth because of QPropertyAnimation. I personally would use QTimeLine and QWidget::move() because with QTimeLine you can set you the Duration and the UpdateIntervall.

    @#ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>

    class QLabel;
    class QPushButton;
    class QPropertyAnimation;

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    public slots:
    void startStopAnimaiton();
    void changeDirection();

    private:
    QLabel* mMovingLabel;
    QPushButton* mStartButton;
    QPropertyAnimation* mMoveAnimation;
    };

    #endif // WIDGET_H@

    @#include <QLabel>
    #include <QPropertyAnimation>
    #include <QPushButton>
    #include <QRect>
    #include "Widget.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent)
    {
    mStartButton = new QPushButton(this);
    mStartButton->setText("Start");

    mMovingLabel = new QLabel;
    mMovingLabel->setText("Moving down");
    mMovingLabel->move(400, 100);
    mMovingLabel->show();

    mMoveAnimation = new QPropertyAnimation(mMovingLabel, "geometry");
    mMoveAnimation->setDuration(5000);
    mMoveAnimation->setStartValue( QRect( QPoint(400, 100), mMovingLabel->size()) );
    mMoveAnimation->setEndValue( QRect( QPoint(400, 800), mMovingLabel->size()) );

    connect( mStartButton, SIGNAL(clicked()), this, SLOT(startStopAnimaiton()) );
    connect( mMoveAnimation, SIGNAL(finished()), this, SLOT(changeDirection()) );

    }

    Widget::~Widget()
    {

    }

    void Widget::startStopAnimaiton()
    {
    if( mMoveAnimation->state() == QVariantAnimation::Running)
    {
    mMoveAnimation->stop();
    mStartButton->setText("Start");
    }
    else
    {
    mMoveAnimation->start();
    mStartButton->setText("Stop");
    }
    }

    void Widget::changeDirection()
    {
    if( mMoveAnimation->direction() == QVariantAnimation::Forward)
    {
    mMoveAnimation->setDirection(QVariantAnimation::Backward);
    mMovingLabel->setText("Moving up");
    }
    else
    {
    mMoveAnimation->setDirection(QVariantAnimation::Forward);
    mMovingLabel->setText("Moving down");
    }

    mMoveAnimation->start();
    }@



  • Oh, i dont know the "QVariantAnimation::Backward" i can do, change the endvalue relanting the value with the size of my widget. thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.