16,203
社区成员
发帖
与我相关
我的任务
分享
import Qt 4.7
Rectangle {
id: screen
property int pixelSize: screen.height * 1.25
property color textColor: "lightsteelblue"
property string text: "Hello world! "
width: 640; height: 320
color: "steelblue"
Row {
y: -screen.height / 4.5
NumberAnimation on x { from: 0; to: -text.width; duration: 6000; loops: Animation.Infinite }
Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
}
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <string>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected slots:
void TimeOut();
private:
QTimer *timer;
std::string temp_str;
int pos;
Ui::MainWindow *ui;
};
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
timer=new QTimer(this);
QObject::connect(timer,SIGNAL(timeout()),this,SLOT(TimeOut()));
timer->start(500);
temp_str="hello,world,this is scroll text!!";
pos=0;
}
void MainWindow::TimeOut()
{
if(pos>temp_str.length())
pos=0;
ui->label->setText(temp_str.substr(pos).c_str());
pos++;
}
MainWindow::~MainWindow()
{
delete ui;
}