Text Scrolling (Marquee effect)



  • Hello, I am trying to scroll text within a QLabel... I did some code, but its not working as it supposed to do... What I want to do is something like this !http://i.stack.imgur.com/I7yXN.png(s)!

    Right now, my code is moving whole lablel left and right... I would like to animate text inside the label and when it hits end of the label, text should start disappearing (like on the image above) and appearing on the other side of label...

    Also my code is moving left and right, instead of disappearing on right side, and then back appear on the left... I believe my code is not correct for this kind of animation... So please can someone help me to make it work as I want...

    @#include "mplayer.h"
    #include "ui_mplayer.h"
    #include <QGraphicsScene>
    #include <QPropertyAnimation>
    #include <QGraphicsTextItem>
    MPlayer::MPlayer(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MPlayer)
    {
    ui->setupUi(this);

    ui->pushButton->setText("Start");

    ui->songLabel->setText("Moving right");
    ui->songLabel->move(300, 100);
    ui->songLabel->show();

    mMoveAnimation = new QPropertyAnimation(ui->songLabel, "geometry");
    mMoveAnimation->setDuration(5000);
    //mMoveAnimation->setStartValue( QRect( QPoint(400, 100), ui->songLabel->size()) );
    //mMoveAnimation->setEndValue( QRect( QPoint(400, 800), ui->songLabel->size()) );
    mMoveAnimation->setStartValue(QRect(QPoint(100, 0), ui->songLabel->size()));
    mMoveAnimation->setEndValue(QRect(QPoint(200,0), ui->songLabel->size()));

    connect( ui->pushButton, SIGNAL(clicked()), this, SLOT(startStopAnimaiton()) );
    connect( mMoveAnimation, SIGNAL(finished()), this, SLOT(changeDirection()) );
    }

    MPlayer::~MPlayer()
    {
    delete ui;
    }

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

    void MPlayer::changeDirection()
    {

    if( mMoveAnimation->direction() == QVariantAnimation::Forward)
    {
    mMoveAnimation->setDirection(QVariantAnimation::Backward);
    ui->songLabel->setText("Moving left");
    }
    else
    {
    mMoveAnimation->setDirection(QVariantAnimation::Forward);
    ui->songLabel->setText("Moving right");
    }

    mMoveAnimation->start();
    }
    @


Log in to reply
 

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