scrollcaption.cpp
#include "widget.h"
#include "ui_widget.h"
#pragma execution_character_set("utf-8")
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
m_scrollCaptionStr = QStringLiteral("欢迎加入我们:Qt分享&&交流 26197884");
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollCaption()));
m_timer->start(50);
}
Widget::~Widget()
{
delete ui;
}
void Widget::scrollCaption()
{
//mothod 1(not sequential)
static int nPos = 0;
if (nPos > m_scrollCaptionStr.length())
{
nPos = 0;
}
ui->m_scrollCaptionLabel->setText(m_scrollCaptionStr.mid(nPos));
nPos++;
//mothod 2(not universal)
ui->m_scrollCaptionLabel_2->setText(m_scrollCaptionStr);
if(ui->m_scrollCaptionLabel_2->pos().x() + ui->m_scrollCaptionLabel_2->width() < 0)
{
ui->m_scrollCaptionLabel_2->move(width(), ui->m_scrollCaptionLabel_2->pos().y());
}
ui->m_scrollCaptionLabel_2->move(ui->m_scrollCaptionLabel_2->pos().x()-1, ui->m_scrollCaptionLabel_2->pos().y());
}