一、简述
1、关于验证码
- 验证码随机生成,有一定的识别难度。
- 点击可以切换。
2、解决方案
- 随机生成验证码。
- 验证码中的字符颜色随机变化。
- 验证码区域随机绘制噪点。
- 用已有组件进行重新实现。
- 重写单击事件处理回调函数,实现点击刷新验证码。
二、效果
//验证码部分是继承QLabel实现
三、源码
1、头文件(.h文件)
#ifndef VERIFICATIONCODELABEL_H
#define VERIFICATIONCODELABEL_H
#include <QLabel>
#include <QTimer>
class VerificationCodeLabel : public QLabel
{
Q_OBJECT
public:
VerificationCodeLabel(QWidget *parent=0);
~VerificationCodeLabel();
//返回一个字符串(字母一律都按照小写返回)
QString getVerificationCode() const;
//重写时间处理的回调函数mousePressEvent
void mousePressEvent(QMouseEvent *ev);
public slots:
//公共槽函