当前位置:网站首页>Qt| imitation text floating letter
Qt| imitation text floating letter
2022-07-23 14:49:00 【InfoQ】
the front

Function realization
Timer operation
virtual void timerEvent(QTimerEvent *event);
Text offset implementation
1: Define the text movement timer
2: Trigger every second , Each trigger requires the creation of a new control to display the content .
3: After triggering, the displayed text traversal mode will be shifted upward as a whole , Random numbers will be used in the migration process , Randomly change the size of the text font .
4: Font changes , Cause the width and height of the text to change , With a new width 、 Position after height calculation offset .
First step
The second step
The third step
QCustomLabel *lab = new QCustomLabel(this);
QSize size = lab->SetTextData(m_vetContent[m_nTimerTriggerNumber], 1);
int nTop = (height() - size.height()) / 2;
lab->setGeometry(DistanceLeft, nTop, size.width(), size.height());
lab->show();
m_vetControls.push_font(lab);
Step four
for (int i = 0; i < m_vetControls.size(); i++)
{
QCustomLabel *lab = m_vetControls[i];
QSize size = lab->UpdateZoomStyle(bFontZoom);
QRectF rectF = lab->geometry();
if (nTop == 0)
{
nTop = lab->geometry().top();
}
else
{
nTop = nTop - size.height();
}
lab->move(DistanceLeft, nTop);
}
this->update();
Step five
if (m_nTimerTriggerNumber == m_vetContent.size())
{
killTimer(m_nTimerId);
m_nTimerId = 0;
}
Control self drawing
#pragma once
#include <QLabel>
class QCustomLabel : public QLabel
{
Q_OBJECT
public:
QCustomLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~QCustomLabel();
};
#include "QCustomLabel.h"
QCustomLabel::QCustomLabel(QWidget *parent, Qt::WindowFlags f)
: QLabel(parent, f)
{
}
QCustomLabel::~QCustomLabel()
{
}
function 1:
QTime time = QTime::currentTime();
qsrand(time.msec() + time.second() * 1000);
int nFontSize = qrand() % 30 + 20;
QFont fontContent =this->font();
// Set up : Font style : Microsoft YaHei
fontContent.setFamily("Microsoft YaHei");
// Set up : font size :22
fontContent.setPixelSize(nFontSize);
// Font binding
this->setFont(fontContent);
QFontMetrics metrics(font());
int nheight = metrics.height();
// Set content and store text content
m_qsTextContent = QString::fromLocal8Bit(sText.c_str());
setFixedHeight(nheight);
this->setText(m_qsTextContent);
this->adjustSize();
int nwidth = this->width();
// Set customization QLable The width and height of the control
QSize size(nwidth , nheight);
// Turn on timer
m_nTimerId = startTimer(100);
return size;
function 2:
QFontMetrics metrics(font());
int x = 0;
int y = (height() + metrics.ascent() - metrics.descent()) / 2;
QColor color;
for (int i = 0; i < m_qsTextContent.size(); i++)
{
// Set up : tonal (H)、 saturation (S)、 brightness (Y)
int nIndex = (m_nStep + i) % 16;
color.setHsv((15 - nIndex) * 16, 255, 191);
painter->setPen(color);
// Single character drawing
painter->drawText(x, y, QString(m_qsTextContent[i]));
// Calculate the of the next character x Coordinate starting point
x += metrics.width(m_qsTextContent[i]);
}
summary
边栏推荐
- Game (2) of 2022 Henan Mengxin League: solution to supplementary questions of Henan University of Technology
- 中望CAD专业版 2022软件安装包下载及安装教程
- [pyqt5 installation and use]
- 基于nextcloud构建个人网盘
- Yunna | how to manage the fixed assets of the company? How to manage the company's fixed assets better?
- [applet automation minium] III. element positioning - use of wxss selector
- Quanzhi f1c100s/f1c200s learning notes (13) -- lvgl transplantation
- Sword finger offer 46. translate numbers into strings
- Some libraries that can perform 2D or 3D triangulation
- 全志F1C100S/F1C200S学习笔记(13)——LVGL移植
猜你喜欢

Quick introduction to PKI system

【 langage c】 devinez jeux numériques + applet d'arrêt

What is per title encoding?

CAN总线快速了解

【测试平台开发】十七、接口编辑页面实现下拉级联选择,绑定接口所属模块...

21 - 二叉树的垂直遍历

LZ77文件压缩

Zhongwang CAD professional 2022 software installation package download and installation tutorial

对象使用过程中背后调用了哪些方法

mysql 之general_log日志
随机推荐
【小程序自动化Minium】一、框架介绍和环境搭建
建议思源笔记能够兼容第三方同步盘
Palindrome related topics
10 years of software testing engineer experience, very confused
Sword finger offer 46. translate numbers into strings
FFmpeg 2 - ffplay、ffprobe、ffmpeg 命令使用
[software test] redis abnormal test encountered in disk-to-disk work
【测试平台开发】21. 完成发送接口请求显示响应头信息
Chapitre 2 requête de base et tri
【我可以做你的第一个项目吗?】GZIP的细节简介和模拟实现
【数组&&字符串&&宏练习题】
koa框架的使用
反射调用事务方法导致事务失效
優化華為雲服務器采用Key登陸
【测试平台开发】二十、完成编辑页发送接口请求功能
Quick introduction to PKI system
How can manual testing turn to automated testing? Byte 5 years of automation experience talk about
关于flex布局justify-content:space-around最后一个不对齐的解决方法和为什么这样子解决是讨论
ArgoCD 用户管理、RBAC 控制、脚本登录、App 同步
R语言实战应用案例:绘图篇(三)-多种组合图型绘制