Qt之实现文字滚动效果

一.效果

二.实现

roller.h

#ifndef ROLLER_H
#define ROLLER_H

#include <QWidget>
#include <QPaintEvent>
#include <QShowEvent>
#include <QHideEvent>
#include <QTimer>

class Roller : public QWidget
{
public:
    explicit Roller(QWidget *parent = nullptr);

    void setText(const QString &text);

protected:
    QSize sizeHint() const override;
    void paintEvent(QPaintEvent* event) override;
    void showEvent(QShowEvent* event) override;
    void hideEvent(QHideEvent* event) override;

private:
    QString m_text;
    int m_offset;
    QTimer m_timer;
};

#endif // ROLLER_H

roller.cpp

#include "roller.h"

#include <QPainter>
#include <QFontMetrics>

Roller::Roller(QW

相关推荐

  1. QT:使用QStyle实现QMenu的滚动效果

    2023-12-09 21:34:02       54 阅读
  2. 纯css实现文字左右循环滚动播放效果

    2023-12-09 21:34:02       42 阅读
  3. 使用Qt实现文本闪烁效果

    2023-12-09 21:34:02       62 阅读
  4. vue实现列表自动滚动效果

    2023-12-09 21:34:02       59 阅读
  5. iOS 实现悬浮跟手滚动效果

    2023-12-09 21:34:02       44 阅读
  6. elment-table实现滚动效果

    2023-12-09 21:34:02       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-09 21:34:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-09 21:34:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-09 21:34:02       82 阅读
  4. Python语言-面向对象

    2023-12-09 21:34:02       91 阅读

热门阅读

  1. linux 编译安装libzmq

    2023-12-09 21:34:02       53 阅读
  2. springboot基础(81):设置redis序列化器

    2023-12-09 21:34:02       58 阅读
  3. 写在FastAPI之旅之前

    2023-12-09 21:34:02       55 阅读
  4. ELK的日志解决方案

    2023-12-09 21:34:02       55 阅读
  5. 六部十层电梯论文

    2023-12-09 21:34:02       53 阅读
  6. Flink 系列文章汇总索引

    2023-12-09 21:34:02       45 阅读
  7. 有关Nginx docker容器版部署访问403的解决

    2023-12-09 21:34:02       57 阅读
  8. 卷积之后通道数为什么变了

    2023-12-09 21:34:02       47 阅读
  9. Docker实战笔记 一 Nginx镜像

    2023-12-09 21:34:02       52 阅读
  10. LightDB - 支持 curdate, current_date 函数[mysql兼容]

    2023-12-09 21:34:02       60 阅读
  11. 笙默考试管理系统-MyExamTest----codemirror(48)

    2023-12-09 21:34:02       39 阅读
  12. 用C语言实现计算器功能

    2023-12-09 21:34:02       54 阅读