#include <QtGui>
{
Q_OBJECT
public:
layout->addWidget(textEdit);
layout->addWidget(pushButton);
central->setLayout(layout);
setCentralWidget(central);
connect(pushButton, SIGNAL(clicked()),SLOT(start()));
}
public slots:
void start(){
text->setDocument(textEdit->document());
text->scale(6,6);
text->setPos(-100,0);
text->setTextWidth(140);
scene->addItem(text);
scene->setSceneRect(0,0,400,400);
view->fitInView(view->sceneRect(),Qt::KeepAspectRatio);
view
->setRenderHint
(QPainter::SmoothPixmapTransform);
view->showFullScreen();
// the important part:
QPropertyAnimation *anim = new QPropertyAnimation(text, "pos", text);
anim->setStartValue(text->pos());
anim
->setEndValue
(QPointF(-100,
-1000));
anim->setDuration(5000);
anim->start();
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0) : QMainWindow(parent){
QVBoxLayout* layout = new QVBoxLayout();
pushButton = new QPushButton("start");
textEdit = new QTextEdit();
layout->addWidget(textEdit);
layout->addWidget(pushButton);
QWidget* central = new QWidget();
central->setLayout(layout);
setCentralWidget(central);
connect(pushButton, SIGNAL(clicked()),SLOT(start()));
}
QGraphicsView* view;
QGraphicsTextItem * text ;
QGraphicsScene* scene;
QPushButton* pushButton;
QTextEdit* textEdit;
public slots:
void start(){
scene = new QGraphicsScene();
text = new QGraphicsTextItem();
text->setDocument(textEdit->document());
text->scale(6,6);
text->setPos(-100,0);
text->setTextWidth(140);
scene->addItem(text);
scene->setSceneRect(0,0,400,400);
view = new QGraphicsView(scene);
view->fitInView(view->sceneRect(),Qt::KeepAspectRatio);
view->setRenderHint(QPainter::SmoothPixmapTransform);
view->showFullScreen();
// the important part:
QPropertyAnimation *anim = new QPropertyAnimation(text, "pos", text);
anim->setStartValue(text->pos());
anim->setEndValue(QPointF(-100, -1000));
anim->setDuration(5000);
anim->start();
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks