#include "qtextscroll.h"
#include <QPainter>
#include <QDebug>
QTextScroll::QTextScroll(QWidget *parent):
QLabel(parent)
{
stepTime = 20;
stepWidth = 1;
curIndex = 0;
scrollTimer = new QTimer();
connect(scrollTimer, SIGNAL(timeout()), this, SLOT(updateIndex()));
}
void QTextScroll::showScrollText(QString text)//public接口,设置要滚动的文字,并开始滚动
{
if(scrollTimer->isActive())
scrollTimer->stop();
showText = text;
scrollTimer->start(stepTime);
}
void QTextScroll::updateIndex()//刷新滚动参数curIndex
{
update();
curIndex++;
if (curIndex*stepWidth > width())
curIndex = 0;
}
void QTextScroll::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
QPainter painter(this);
painter.drawText(0-stepWidth*curIndex, 100, showText);//画左半部分的文字
painter.drawText(width() - stepWidth*curIndex, 100, showText.left(curIndex));//画右半部分的文字
}
QT跑马字幕
需积分: 43 164 浏览量
2017-09-30
14:38:57
上传
评论 2
收藏 2KB GZ 举报
birdman_1992
- 粉丝: 4
- 资源: 6
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈