最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Qt編寫顯示密碼強(qiáng)度的控件

 更新時間:2022年06月14日 14:08:13   作者:友善啊,朋友  
這篇文章主要為大家詳細(xì)介紹了Qt編寫顯示密碼強(qiáng)度的控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Qt編寫顯示密碼強(qiáng)度控件的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

#ifndef WIDGET_H
#define WIDGET_H
?
#include <QWidget>
#include <QRegularExpression>
#include <QTimer>
?
class PasswordStrengthCheck : public QWidget
{
? ? Q_OBJECT
?
public:
? ? PasswordStrengthCheck(QWidget *parent = nullptr);
? ? ~PasswordStrengthCheck();
? ? virtual QSize minimumSizeHint() const override;
? ? void onLineEditTextChanged(const QString &text);
?
protected:
? ? void paintEvent(QPaintEvent *event)override;
?
private:
? ? void onTimer();
? ? QRegularExpression lowRegularExpression;
? ? QRegularExpression mediumRegularExpression;
? ? QRegularExpression highRegularExpression;
? ? double targetRatio{0};
? ? double nowRatio{0};
? ? QTimer timer;
};
#endif // WIDGET_H
#include "widget.h"
#include <QPainter>
#include <QPaintEvent>
#include <QPainterPath>
?
PasswordStrengthCheck::PasswordStrengthCheck(QWidget *parent)
? ? : QWidget(parent)
{
? ? lowRegularExpression = QRegularExpression("[A-Z][a-z][A-Za-z0-9_]{4,6}");
? ? mediumRegularExpression = QRegularExpression("[A-Z][a-z][A-Za-z0-9_]{7,9}");
? ? highRegularExpression = QRegularExpression("[A-Z][a-z][A-Za-z0-9_]{10,12}");
?
? ? connect(&timer,&QTimer::timeout,this,&PasswordStrengthCheck::onTimer);
? ? timer.setInterval(40);
}
?
PasswordStrengthCheck::~PasswordStrengthCheck()
{
}
?
QSize PasswordStrengthCheck::minimumSizeHint() const
{
? ? return QSize(100,30);
}
?
void PasswordStrengthCheck::onLineEditTextChanged(const QString & text)
{
? ? if(highRegularExpression.match(text).hasMatch())
? ? {
? ? ? ? targetRatio = 1;
? ? }
? ? else if(mediumRegularExpression.match(text).hasMatch())
? ? {
? ? ? ? targetRatio = 0.66;
? ? }
? ? else if(lowRegularExpression.match(text).hasMatch())
? ? {
? ? ? ? targetRatio = 0.33;
? ? }
? ? else
? ? {
? ? ? ? targetRatio = 0;
? ? }
? ? timer.start();
}
?
void PasswordStrengthCheck::paintEvent(QPaintEvent *event)
{
? ? QPainter painter(this);
? ? painter.setRenderHint(QPainter::Antialiasing,true);
? ? const auto rect = event->rect();
?
? ? auto width = rect.width();
? ? auto height = rect.height();
? ? painter.setBrush(Qt::white);
? ? painter.setPen(QPen(QBrush("#128bf1"),3));
?
? ? int radiu = 3;
? ? QRect borderRect = QRect(width*0.05,0,width*0.9,height).adjusted(radiu,radiu,-radiu,-radiu);
? ? painter.drawRoundedRect(borderRect,radiu,radiu);
?
? ? QPainterPath path;
? ? path.addRoundedRect(borderRect.adjusted(radiu,radiu,-radiu,-radiu),radiu,radiu);
? ? QPainterPath path2;
? ? path2.addRect(QRect(QPoint(borderRect.x() + borderRect.width() * 0.3,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?borderRect.y()),borderRect.bottomRight()));
?
? ? QPainterPath path_left = path - path2;
?
? ? path2.clear();
? ? path2.addRect(QRect(borderRect.topLeft(),
? ? ? ? ? ? ? ? ? ? ? ? QPoint(borderRect.x() + borderRect.width() * 0.7,borderRect.bottom())));
? ? QPainterPath path_right = path - path2;
?
? ? QRect mediumRect = QRect(QPoint(borderRect.x() + borderRect.width() * 0.35,borderRect.top()),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?QPoint(borderRect.bottomRight() - QPoint(borderRect.width() * 0.35,0))).adjusted(0,radiu,0,-radiu);
?
? ? QPixmap greyPixmap(rect.size());
? ? {
? ? ? ? greyPixmap.fill(Qt::transparent);
? ? ? ? QPainter painter(&greyPixmap);
? ? ? ? QBrush brush("#CDCDCD");
? ? ? ? painter.setRenderHint(QPainter::Antialiasing,true);
? ? ? ? painter.fillPath(path_left,brush);
? ? ? ? painter.fillPath(path_right,brush);
? ? ? ? painter.fillRect(mediumRect,brush);
? ? }
? ? painter.drawPixmap(rect,greyPixmap);
?
? ? if(nowRatio > 0)
? ? {
? ? ? ? QPixmap colorPixmap(QSize(width * nowRatio,height));
? ? ? ? {
? ? ? ? ? ? colorPixmap.fill(Qt::transparent);
? ? ? ? ? ? QPainter painter(&colorPixmap);
? ? ? ? ? ? painter.setRenderHint(QPainter::Antialiasing,true);
? ? ? ? ? ? painter.fillPath(path_left,QBrush("#EC3700"));
? ? ? ? ? ? painter.fillPath(path_right,QBrush("#F78115"));
? ? ? ? ? ? painter.fillRect(mediumRect,QBrush("#6AA000"));
? ? ? ? }
? ? ? ? painter.drawPixmap(QPoint(0,0),colorPixmap);
? ? }
}
?
void PasswordStrengthCheck::onTimer()
{
? ? static double e=0.0002;
?
? ? if(fabs(targetRatio - nowRatio) < e)
? ? {
? ? ? ? timer.stop();
? ? ? ? return;
? ? }
?
? ? if(nowRatio < targetRatio)
? ? {
? ? ? ? nowRatio += 0.02;
? ? }
? ? else
? ? {
? ? ? ? nowRatio -= 0.02;
? ? }
? ? update();
}

使用:

#include "widget.h"
#include <QApplication>
#include <QLineEdit>
#include <QFormLayout>
?
int main(int argc, char *argv[])
{
? ? QApplication a(argc, argv);
?
? ? QWidget w;
? ? QLineEdit * lineEdit = new QLineEdit;
? ? PasswordStrengthCheck * c = new PasswordStrengthCheck;
? ? QObject::connect(lineEdit,&QLineEdit::textChanged,c,&PasswordStrengthCheck::onLineEditTextChanged);
? ? QFormLayout * layout = new QFormLayout(&w);
? ? layout->addRow("密碼:",lineEdit);
? ? layout->addRow("",c);
? ? w.show();
? ? return a.exec();
}

效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++中構(gòu)造函數(shù)的參數(shù)缺省的詳解

    C++中構(gòu)造函數(shù)的參數(shù)缺省的詳解

    這篇文章主要介紹了C++中構(gòu)造函數(shù)的參數(shù)缺省的詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • Opencv學(xué)習(xí)教程之漫水填充算法實例詳解

    Opencv學(xué)習(xí)教程之漫水填充算法實例詳解

    這篇文章主要給大家介紹了Opencv學(xué)習(xí)教程之漫水填充算法的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),對大家具有一定的參考價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-06-06
  • 介紹C語言中tolower函數(shù)的實例

    介紹C語言中tolower函數(shù)的實例

    這篇文章主要介紹了介紹C語言中tolower函數(shù)的實例,本文列出了該函數(shù)的頭文件,功能說明等,以及如何使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 利用C語言實現(xiàn)任務(wù)調(diào)度的示例代碼

    利用C語言實現(xiàn)任務(wù)調(diào)度的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用純C語言實現(xiàn)任務(wù)調(diào)度(可用于STM32、C51等單片機(jī)),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2023-04-04
  • C語言實現(xiàn)考試報名管理系統(tǒng)

    C語言實現(xiàn)考試報名管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了C語言實現(xiàn)考試報名管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • WIN32程序獲取父進(jìn)程ID的方法

    WIN32程序獲取父進(jìn)程ID的方法

    這篇文章主要介紹了WIN32程序獲取父進(jìn)程ID的方法,在進(jìn)行windows程序開發(fā)的時候有一定的實用價值,需要的朋友可以參考下
    2014-08-08
  • C語言中使用lex統(tǒng)計文本文件字符數(shù)

    C語言中使用lex統(tǒng)計文本文件字符數(shù)

    這篇文章主要介紹了C語言中使用lex統(tǒng)計文本文件字符數(shù),本文直接給出實現(xiàn)代碼,需要的朋友可以參考下
    2015-04-04
  • C語言數(shù)據(jù)的存儲超詳細(xì)講解上篇

    C語言數(shù)據(jù)的存儲超詳細(xì)講解上篇

    使用編程語言進(jìn)行編程時,需要用到各種變量來存儲各種信息。變量保留的是它所存儲的值的內(nèi)存位置。這意味著,當(dāng)您創(chuàng)建一個變量時,就會在內(nèi)存中保留一些空間。您可能需要存儲各種數(shù)據(jù)類型的信息,操作系統(tǒng)會根據(jù)變量的數(shù)據(jù)類型,來分配內(nèi)存和決定在保留內(nèi)存中存儲什么
    2022-04-04
  • 一篇文章帶你了解C語言文件操作中的幾個函數(shù)

    一篇文章帶你了解C語言文件操作中的幾個函數(shù)

    這篇文章主要介紹了使用C語言操作文件的基本函數(shù)整理,包括創(chuàng)建和打開以及關(guān)閉文件的操作方法,需要的朋友可以參考下,希望能夠給你帶來幫助
    2021-09-09
  • C++結(jié)合QT實現(xiàn)帶有優(yōu)先級的計算器功能

    C++結(jié)合QT實現(xiàn)帶有優(yōu)先級的計算器功能

    這篇文章主要介紹了C++結(jié)合QT實現(xiàn)帶有優(yōu)先級的計算器,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01

最新評論

秦皇岛市| 桂阳县| 休宁县| 平阴县| 泰兴市| 钟山县| 安远县| 曲靖市| 五原县| 星子县| 雷州市| 平果县| 揭东县| 共和县| 永泰县| 纳雍县| 祁连县| 阿拉善右旗| 阿瓦提县| 上杭县| 清远市| 思茅市| 天津市| 晋城| 乐都县| 浦北县| 漳州市| 常熟市| 顺义区| 嘉峪关市| 潞西市| 水富县| 莱州市| 玉田县| 新乡县| 迁安市| 远安县| 通化县| 自贡市| 泗水县| 富源县|