//file: mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QGraphicsTextItem>
#include <QPushButton>
#include <QTextEdit>
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QTimeLine>
#include <QTimer>
#include <QTime>
#include <QRect>
#include <QPushButton>
#include <QVBoxLayout>
{
Q_OBJECT
public:
layout->addWidget(textEdit);
layout->addWidget(pushButton);
central->setLayout(layout);
setCentralWidget(central);
connect(pushButton, SIGNAL(clicked()),SLOT(start()));
}
~MainWindow(){
}
QTime* timeSinceLastUpdate;
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();
connect(sctT,SIGNAL(timeout()),SLOT(scroll()));
sctT->start(30);
timeSinceLastUpdate
= new QTime();
timeSinceLastUpdate->start();
}
void scroll(){
int time = timeSinceLastUpdate->elapsed(); //make the scrolling indipendent from frame rate
float scrollValue = (40.0 * float(time))/1000.0;
text->translate(0,-scrollValue);
timeSinceLastUpdate->restart();
}
};
#endif // MAINWINDOW_H
file: main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
//file: mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QApplication>
#include <QMainWindow>
#include <QGraphicsTextItem>
#include <QPushButton>
#include <QTextEdit>
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QTimeLine>
#include <QTimer>
#include <QTime>
#include <QRect>
#include <QPushButton>
#include <QVBoxLayout>
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()));
}
~MainWindow(){
}
QGraphicsView* view;
QGraphicsTextItem * text ;
QGraphicsScene* scene;
QPushButton* pushButton;
QTextEdit* textEdit;
QTime* timeSinceLastUpdate;
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();
QTimer* sctT = new QTimer();
connect(sctT,SIGNAL(timeout()),SLOT(scroll()));
sctT->start(30);
timeSinceLastUpdate = new QTime();
timeSinceLastUpdate->start();
}
void scroll(){
int time = timeSinceLastUpdate->elapsed(); //make the scrolling indipendent from frame rate
float scrollValue = (40.0 * float(time))/1000.0;
text->translate(0,-scrollValue);
timeSinceLastUpdate->restart();
}
};
#endif // MAINWINDOW_H
file: main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
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