您的位置:首页 > 其它

窗体部件效果之滚动字幕

2017-08-02 17:50 260 查看
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());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: