Archived:Como criar uma animação simples usando QTimeLine
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Este trecho de código mostra como criar uma animação simples em Qt. É empregada a classe QTimeLine, capaz de prover uma linha de tempo para controlar animações.
Dados do artigo
Testado com
Aparelho(s): Emulator
Compatibilidade
Plataforma(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Artigo
Palavras-chave: QTimeLine,QProgressBar
Tradução:
Por valderind4
Última alteração feita por hamishwillee
em 18 Jun 2012
Contents |
Funcionalidades
- Esta propriedade mantem a direção da linha do tempo enquanto o está em estado de execução. O padrão é avançar.
timeLine->setDirection(QTimeLine::Backward);
- Esta propriedade tem a forma da curva da linha do tempo.
timeLine->setCurveShape(QTimeLine::EaseInCurve);
- Para adicionar um Pause para pausar a TimeLine você deve adicionar o seguinte código no seu código fonte.
connect(pushButton1, SIGNAL(clicked()), this, SLOT(viral()));
Adicione esta funcionalidade para o seu código atual.
void timeline::viral( timeLine->setPaused(1); }
Trecho de código
Código fonte
#include "timeline.h"
timeline::timeline(QWidget *parent)
: QWidget(parent)
{
layout= new QVBoxLayout(this);
progressBar = new QProgressBar(this);
progressBar->setRange(0, 100);
// Construct a 5-second timeline with a frame range of 0 - 100
timeLine = new QTimeLine(5000, this);
timeLine->setFrameRange(0, 100);
connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
// Clicking the push button will start the progress bar animation
pushButton = new QPushButton(tr("Start animation"), this);
connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
layout->addWidget(progressBar);
layout->addWidget(pushButton);
setLayout(layout);
}
timeline::~timeline()
{
// No need to delete any QObject that got proper parent pointer.
}
Arquivos de cabeçalhos
#ifndef TIMELINE_H
#define TIMELINE_H
#include <QtGui/QWidget>
#include "ui_timeline.h"
#include <QVBoxLayout>
#include <QTimeLine>
#include <QProgressBar>
#include <QPushButton>
class timeline : public QWidget
{
Q_OBJECT
public:
timeline(QWidget *parent = 0);
~timeline();
private:
QPushButton *pushButton;
QTimeLine *timeLine;
QProgressBar *progressBar;
QVBoxLayout *layout;
};
#endif // TIMELINE_H
Captura de tela
Para mais detalhes visite:este link(Inglês)



