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

Qt實(shí)現(xiàn)密碼顯示按鈕

 更新時(shí)間:2022年06月14日 16:45:53   作者:蝦球xz  
這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)密碼顯示按鈕,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Qt實(shí)現(xiàn)密碼顯示按鈕的具體代碼,供大家參考,具體內(nèi)容如下

PasswordLineEdit.h

#ifndef PASSWORDLINEEDIT_H
#define PASSWORDLINEEDIT_H

#include <QAction>
#include <QLineEdit>
#include <QToolButton>

class PasswordLineEdit : public QLineEdit {
public:
? PasswordLineEdit(QWidget *parent = nullptr);
private slots:
? void onPressed();
? void onReleased();

protected:
? void enterEvent(QEvent *event);
? void leaveEvent(QEvent *event);
? void focusInEvent(QFocusEvent *event);
? void focusOutEvent(QFocusEvent *event);

private:
? QToolButton *button;
};

#endif // PASSWORDLINEEDIT_H

PasswordLineEdit.cpp

#include "passwordlineedit.h"

PasswordLineEdit::PasswordLineEdit(QWidget *parent) : QLineEdit(parent)
{
? ? setEchoMode(QLineEdit::Password);
? ? QAction *action = addAction(QIcon(":/eyeOff"), QLineEdit::TrailingPosition);
? ? button = qobject_cast<QToolButton *>(action->associatedWidgets().last());
? ? button->hide();
? ? button->setCursor(QCursor(Qt::PointingHandCursor));
? ? connect(button, &QToolButton::pressed, this, &PasswordLineEdit::onPressed);
? ? connect(button, &QToolButton::released, this, &PasswordLineEdit::onReleased);
}

void PasswordLineEdit::onPressed()
{
? ? QToolButton *button = qobject_cast<QToolButton *>(sender());
? ? button->setIcon(QIcon(":/eyeOn"));
? ? setEchoMode(QLineEdit::Normal);
}

void PasswordLineEdit::onReleased()
{
? ? QToolButton *button = qobject_cast<QToolButton *>(sender());
? ? button->setIcon(QIcon(":/eyeOff"));
? ? setEchoMode(QLineEdit::Password);
}

void PasswordLineEdit::enterEvent(QEvent *event)
{
? ? button->show();
? ? QLineEdit::enterEvent(event);
}

void PasswordLineEdit::leaveEvent(QEvent *event)
{
? ? button->hide();
? ? QLineEdit::leaveEvent(event);
}

void PasswordLineEdit::focusInEvent(QFocusEvent *event)
{
? ? button->show();
? ? QLineEdit::focusInEvent(event);
}

void PasswordLineEdit::focusOutEvent(QFocusEvent *event)
{
? ? button->hide();
? ? QLineEdit::focusOutEvent(event);
}

main.cpp

#include "passwordlineedit.h"

#include <QApplication>
#include <QFormLayout>

int main(int argc, char *argv[])
{
? ? QApplication a(argc, argv);

? ? QWidget w;
? ? PasswordLineEdit *w1 = new PasswordLineEdit;
? ? QLineEdit *w2 = new QLineEdit;
? ? QFormLayout *lay = new QFormLayout(&w);
? ? lay->addRow("PasswordLineEdit: ", w1);
? ? lay->addRow("QLineEdit: ", w2);
? ? w.show();

? ? return a.exec();
}

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

相關(guān)文章

  • 一文掌握C++ const與constexpr及區(qū)別

    一文掌握C++ const與constexpr及區(qū)別

    C++ 11標(biāo)準(zhǔn)中,const 用于為修飾的變量添加“只讀”屬性而 constexpr關(guān)鍵字則用于指明其后是一個(gè)常量,編譯器在編譯程序時(shí)可以順帶將其結(jié)果計(jì)算出來(lái),而無(wú)需等到程序運(yùn)行階段,這樣的優(yōu)化極大地提高了程序的執(zhí)行效率,本文重點(diǎn)介紹C++ const與constexpr區(qū)別介紹,一起看看吧
    2024-02-02
  • OpenCV實(shí)現(xiàn)人臉識(shí)別簡(jiǎn)單程序

    OpenCV實(shí)現(xiàn)人臉識(shí)別簡(jiǎn)單程序

    這篇文章主要為大家詳細(xì)介紹了OpenCV實(shí)現(xiàn)人臉識(shí)別簡(jiǎn)單程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • C++?const與constexpr區(qū)別小結(jié)

    C++?const與constexpr區(qū)別小結(jié)

    C++11標(biāo)準(zhǔn)中,const用于為修飾的變量添加只讀屬性,而constexpr關(guān)鍵字則用于指明其后是一個(gè)常量,本文主要介紹了C++?const與constexpr區(qū)別小結(jié),感興趣的可以了解一下
    2024-03-03
  • C++單例模式應(yīng)用實(shí)例

    C++單例模式應(yīng)用實(shí)例

    這篇文章主要介紹了C++單例模式應(yīng)用實(shí)例,詳細(xì)講述了單例模式的原理與結(jié)構(gòu),及相關(guān)的打印機(jī)應(yīng)用實(shí)例,需要的朋友可以參考下
    2014-10-10
  • C++動(dòng)態(tài)規(guī)劃中關(guān)于背包問題講解

    C++動(dòng)態(tài)規(guī)劃中關(guān)于背包問題講解

    可能有些讀者有接觸過(guò)動(dòng)態(tài)規(guī)劃,可能也有一些讀者以前完全不知道動(dòng)態(tài)規(guī)劃這個(gè)東西,別擔(dān)心,我這篇文章會(huì)為讀者做一個(gè)入門,好讓讀者掌握這個(gè)重要的知識(shí)點(diǎn)
    2023-03-03
  • 詳細(xì)分析C++ 多態(tài)和虛函數(shù)

    詳細(xì)分析C++ 多態(tài)和虛函數(shù)

    這篇文章主要介紹了C++ 多態(tài)和虛函數(shù)的相關(guān)資料,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • 基于C語(yǔ)言實(shí)現(xiàn)的aes256加密算法示例

    基于C語(yǔ)言實(shí)現(xiàn)的aes256加密算法示例

    這篇文章主要介紹了基于C語(yǔ)言實(shí)現(xiàn)的aes256加密算法,結(jié)合具體實(shí)例形式詳細(xì)分析了C語(yǔ)言實(shí)現(xiàn)的aes256加密算法實(shí)現(xiàn)步驟與使用技巧,需要的朋友可以參考下
    2017-02-02
  • 由static_cast和dynamic_cast到C++對(duì)象占用內(nèi)存的全面分析

    由static_cast和dynamic_cast到C++對(duì)象占用內(nèi)存的全面分析

    下面小編就為大家?guī)?lái)一篇由static_cast和dynamic_cast到C++對(duì)象占用內(nèi)存的全面分析。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • vscode+platformIO開發(fā)stm32f4的實(shí)現(xiàn)

    vscode+platformIO開發(fā)stm32f4的實(shí)現(xiàn)

    這篇文章主要介紹了vscode+platformIO開發(fā)stm32f4的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • C++構(gòu)造函數(shù)一些常見的坑

    C++構(gòu)造函數(shù)一些常見的坑

    這篇文章主要給大家分享的是C++構(gòu)造函數(shù)一些常見的坑,文章圍繞C++構(gòu)造函數(shù)的相關(guān)資料展開關(guān)于C++構(gòu)造函數(shù)坑的內(nèi)容,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-01-01

最新評(píng)論

炉霍县| 神木县| 蓝山县| 舒城县| 永靖县| 大名县| 南宁市| 岑溪市| 彭山县| 岑溪市| 秦皇岛市| 乌拉特前旗| 安庆市| 淮安市| 汕尾市| 光山县| 安庆市| 沅江市| 红安县| 淅川县| 平利县| 赤城县| 松溪县| 康马县| 和龙市| 宝丰县| 翼城县| 读书| 巴楚县| 庄河市| 绩溪县| 林州市| 房产| 定兴县| 临沧市| 格尔木市| 龙游县| 甘泉县| 铜梁县| 正安县| 许昌县|