Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Animation in Label[SOLVED]

Animation in Label[SOLVED]

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 2 Posters 7.2k Views
  • 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.
  • F Offline
    F Offline
    felipe.c.sousa
    wrote on last edited by
    #1

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

    From all, to all.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      messi
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        felipe.c.sousa
        wrote on last edited by
        #3

        @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.

        From all, to all.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          messi
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            felipe.c.sousa
            wrote on last edited by
            #5

            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.

            From all, to all.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              messi
              wrote on last edited by
              #6

              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();
              }@

              1 Reply Last reply
              0
              • F Offline
                F Offline
                felipe.c.sousa
                wrote on last edited by
                #7

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

                From all, to all.

                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