Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Text Scrolling (Marquee effect)
Forum Updated to NodeBB v4.3 + New Features

Text Scrolling (Marquee effect)

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 3.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

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

    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