-
Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathScrollLabel.h
49 lines (42 loc) · 1.08 KB
/
ScrollLabel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef SCROLLLABEL_H
#define SCROLLLABEL_H
#include <QLabel>
#include <QBasicTimer>
//滚动文字的label
class ScrollLabel : public QLabel
{
Q_OBJECT
public:
//滚动方向
enum ScrollDirection{
RightToLeft=1,
LeftToRight=2
};
public:
explicit ScrollLabel(QWidget *parent = nullptr);
//滚动方向
ScrollLabel::ScrollDirection getDirection() const;
void setDirection(ScrollLabel::ScrollDirection direction);
//刷新间隔
int getInterval() const;
void setInterval(int interval);
protected:
//basictimer定时器触发
void timerEvent(QTimerEvent *event) override;
//绘制
void paintEvent(QPaintEvent *event) override;
//大小变化时重新计算
void resizeEvent(QResizeEvent *event) override;
private:
//滚动定时器
//也可以使用QTimer QTimeLine QAnimation等实现
QBasicTimer scrollTimer;
int interval=20;
//偏移量
int offset=0;
int textWidth=0;
int labelWidth=0;
//默认右往左
ScrollDirection direction=RightToLeft;
};
#endif // SCROLLLABEL_H