当前位置: 首页 > news >正文

邮箱官方网站注册最近新闻事件

邮箱官方网站注册,最近新闻事件,国外建设网站情况报告,一品威客网官网网址本文实例为大家分享了Qt自定义一个密码器控件的简单实现代码,供大家参考,具体内容如下 实现构思: 密码器的功能可以看成是计算器和登陆界面的组合,所以在实现功能的过程中借鉴了大神的计算器的实现代码和登陆界面实现的代码。 …

本文实例为大家分享了Qt自定义一个密码器控件的简单实现代码,供大家参考,具体内容如下

实现构思:

密码器的功能可以看成是计算器和登陆界面的组合,所以在实现功能的过程中借鉴了大神的计算器的实现代码和登陆界面实现的代码。

实现的效果:

关于密码器控件的不足:

窗口的标题栏不够漂亮,但是由于对时间长度和任务进度的权衡,下次一定进行重绘。

代码思路:

由于我司不用样式表,所以背景由贴图函数完成。在widget中添加按钮控件和文本编辑控件。使用布局函数进行布局,在加上一些简单的逻辑处理功能即可。

首先创建一个工程文件,添加新文件,选择qt 设计师界面类,如下:

进入创建的ui界面后,添加控件进行布局,单一的使用了珊格布局,如下:

在自定义控件的布局中遇到了一些与布局相关的问题:

问题1:如何改变布局内控件的大小? ui中修改方式如下,纯代码实现也可以去帮助手册中查找相同的接口函数。

问题2:布局中控件的位置如何进行更改?

?

1

2

*ui->gridLayout->setContentsMargins(QMargins(10,60,0,0));

ui->gridLayout->setVerticalSpacing(10);*

具体size,自行可以调整到比较合适的位置。

源码实现:

calculaterform.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

50

51

52

53

54

55

56

57

58

59

60

61

62

63

#define CALCULATERFORM_H

#include "calacutorbutton.h"

#include <QWidget>

#include <QLineEdit>

namespace Ui {

class CalculaterForm;

}

class CalculaterForm : public QWidget

{

? ? Q_OBJECT

public:

? ? explicit CalculaterForm(QWidget *parent = nullptr);

? ? ~CalculaterForm();

? ? ?void ?addLineEdit();

? ? ?void addBackImg();//可以进行提供一个背景图片

private slots:

? ? void on_pushButton_clicked(bool checked);

? ? void on_pushButton_2_clicked(bool checked);

? ? void on_pushButton_3_clicked(bool checked);

? ? void on_pushButton_4_clicked(bool checked);

? ? void on_pushButton_5_clicked(bool checked);

? ? void on_pushButton_6_clicked(bool checked);

? ? void on_pushButton_7_clicked(bool checked);

? ? void on_pushButton_8_clicked(bool checked);

? ? void on_pushButton_9_clicked(bool checked);

? ? void on_pushButton_10_clicked(bool checked);

? ? void on_pushButton_11_clicked(bool checked);

? ? void on_pushButton_12_clicked(bool checked);

? ? void on_pushButton_13_clicked(bool checked);

? ? void on_pushButton_15_clicked(bool checked);

? ? void on_pushButton_14_clicked(bool checked);

private:

? ? Ui::CalculaterForm *ui;

? ? float mNum1,mNum2,mResult;

? ? char mSign;

? ? int mMark;

? ? QString mKeyStr = "0000";//密码字符串

? ? QString S;

? ? QLineEdit *mLineEdit;

};

#endif // CALCULATERFORM_H

calculaterform.cpp

?

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

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

#include "calculaterform.h"

#include "ui_calculaterform.h"

#include <QLineEdit>

#include <QDebug>

#include <QMessageBox>

CalculaterForm::CalculaterForm(QWidget *parent) :

? ? QWidget(parent),

? ? ui(new Ui::CalculaterForm)

{

? ? ui->setupUi(this);

? ? mNum1 = 0.0;

? ? mNum2 = 0.0;

? ? mResult = 0.0;

? ? S="";

? ? mMark=1;

? ? ui->pushButton_13->setMyIcon("/home/rabbitchenc/Image/dialog_cancel.png");

? ? ui->pushButton_14->setMyIcon("/home/rabbitchenc/Image/ime_icon_del.png");

? ? ui->pushButton_15->setMyIcon("/home/rabbitchenc/Image/dialog_ok.png");

? ? mLineEdit = new QLineEdit(this);

? ? setFixedSize(width(),height());

? ? ui->gridLayout->setContentsMargins(QMargins(10,60,0,0));

? ? ui->gridLayout->setVerticalSpacing(10);

? ? addBackImg();

? ? addLineEdit();

? ? ui->pushButton_10->setEnabled(false);

? ? ui->pushButton_12->setEnabled(false);

}

//添加文本编辑

void ?CalculaterForm::addLineEdit()

{

? ? if(mLineEdit != nullptr){

? ? ? ? mLineEdit->resize(width(),40);

? ? ? ? mLineEdit->setStyleSheet("background:transparent;border-width:0;border-style:outset");

? ? ? ? mLineEdit->setAlignment(Qt::AlignHCenter);

? ? ? ? mLineEdit->setEchoMode(QLineEdit::Password);

? ? }

}

//添加背景图片

void CalculaterForm::addBackImg()

{

? ? QString filename = "/home/rabbitchenc/Image/ime_bg.png";

? ? QPixmap pixmap(filename);

? ? QPalette pal;

? ? pixmap = pixmap.scaled(width(),height());

? ? pal.setBrush(QPalette::Window,QBrush(pixmap));

? ? setPalette(pal);

}

CalculaterForm::~CalculaterForm()

{

? ? delete ui;

}

void CalculaterForm::on_pushButton_clicked(bool checked)

{

? ? S += "1";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_2_clicked(bool checked)

{

? ? S += "2";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_3_clicked(bool checked)

{

? ? S += "3";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_4_clicked(bool checked)

{

? ? S += "4";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_5_clicked(bool checked)

{

? ? S += "5";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_6_clicked(bool checked)

{

? ? S += "6";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_7_clicked(bool checked)

{

? ? S += "7";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_8_clicked(bool checked)

{

? ? S += "8";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_9_clicked(bool checked)

{

? ? S += "9";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_10_clicked(bool checked)

{

}

void CalculaterForm::on_pushButton_11_clicked(bool checked)

{

? ? S += "0";

? ? mLineEdit->setText(S);

}

void CalculaterForm::on_pushButton_12_clicked(bool checked)

{

}

void CalculaterForm::on_pushButton_13_clicked(bool checked)

{

? ? this->close();

}

void CalculaterForm::on_pushButton_15_clicked(bool checked)

{

? ? if(S == mKeyStr)

? ? {

? ? ? ? qDebug() << "right";

? ? ? ? this->close();

? ? }else{

? ? ? ? qDebug() << "false";

? ? ? ? QMessageBox *messageBox = new QMessageBox(QMessageBox::Warning,"错误提示","密码错误");

? ? ? ? messageBox->show();

? ? }

}

void CalculaterForm::on_pushButton_14_clicked(bool checked)

{

? ? S = S.left(S.length() - 1);

? ? mLineEdit->setText(S);

}

自定义的按钮源码:
calacutorbutton.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

#ifndef CALACUTORBUTTON_H

#define CALACUTORBUTTON_H

#include <QPushButton>

class CalacutorButton: public QPushButton

{

? ? Q_OBJECT

public:

? ? explicit CalacutorButton(QWidget *parent = nullptr);

? ? ~CalacutorButton();

? ? void setText(const QString&text);

? ? void setMyIcon(const QString&icon);

? ? void setImageName(const QString&img);

? ? void setPressImg(const QString&img);

protected:

? ? void paintEvent(QPaintEvent *event);

? ? void drawText(QPainter *painter);

? ? void drawImage(QPainter*painter);

? ? void drawIcon(QPainter*painter);

? ? QPixmap* ninePatch(QString picName,double iHorzSplit,double iVertSplit, double DstWidth, double DstHeight);

? ? QPixmap generatePixmap(const QPixmap& img_in, int radius1,int radius2);

private:

? ? QString ?mFileName;

? ? QString mPressImgName;

? ? QString mNormalImgName;

? ? QString mFocusImgName;

? ? QString mDisableName;

? ? QString mText;

? ? QString mIcon;

? ? int mWidth;

? ? int mHeight;

? ? bool pressed;

};

#endif // CALACUTORBUTTON_H

calacutorbutton.cpp

?

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

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

#include "calacutorbutton.h"

#include <QPainter>

#include <QBitmap>

#include <QMouseEvent>

#include <QSizePolicy>

//增加对按钮类型的设定

//按钮控件中缺少

CalacutorButton::CalacutorButton(QWidget *parent):QPushButton(parent)

{

? ? pressed = false;

? ? mText = "";

? ? mIcon = "";

? ? mPressImgName = "/home/rabbitchenc/Image/btn_ime.png";

? ? mNormalImgName = "";//不添加图片背景

? ? mFocusImgName = "";

? ? mDisableName = "";

? ? mFileName = mNormalImgName;

? ? connect(this,&QPushButton::pressed,[=](){

? ? ? ? pressed = true;

? ? ? ? setImageName(mPressImgName);

? ? });

? ? connect(this,&QPushButton::released,[=](){

? ? ? ? pressed = false;

? ? ? ? setImageName(mNormalImgName);

? ? });

}

CalacutorButton::~CalacutorButton()

{

}

void CalacutorButton::paintEvent(QPaintEvent *event)

{

?QPainter painter(this);

?painter.setRenderHint(QPainter::Antialiasing);

?painter.setRenderHint(QPainter::TextAntialiasing);

?drawImage(&painter);

?drawText(&painter);

?drawIcon(&painter);

}

void CalacutorButton::drawImage(QPainter*painter)

{

? ? painter->save();

? ? QPixmap pixmap;

? ? mWidth = width();

? ? mHeight = height();

? ? if(isEnabled()){

? ? ? ? if(isCheckable()){

? ? ? ? ? ? if(isChecked()){

? ? ? ? ? ? ? ? mFileName = mPressImgName;

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? mFileName = mNormalImgName;

? ? ? ? ? ? }

? ? ? ? ? ? if(pressed){

? ? ? ? ? ? ? ? mFileName = mFocusImgName;

? ? ? ? ? ? }

? ? ? ? }

? ? }else {

// ? ? ? ?mFileName = mDisableName;

}

? ? pixmap = QPixmap( mFileName);

? ? painter->drawPixmap(0,0,mWidth,mHeight,pixmap);

? ? painter->restore();

}

?//添加文字

? void CalacutorButton::drawText(QPainter *painter)

? {

? ? ? painter->save();

? ? ? QFont font = painter->font();

? ? ? painter->drawText(0,0,mWidth,mHeight,Qt::AlignCenter,mText);

? ? ? painter->restore();

? }

? //添加图标

? void CalacutorButton::drawIcon(QPainter*painter)

? {

? ? ? painter->save();

? ? ? QPixmap pixmap(mIcon);

? ? ? if(pressed){

? ? ? ? ? painter->drawPixmap((width()-pixmap.width())/2,(height()-pixmap.height())/2,pixmap.width(),pixmap.height(),pixmap);

? ? ? }else{

? ? ? ? ? painter->drawPixmap((width()-pixmap.width())/2,(height()-pixmap.height())/2,pixmap.width(),pixmap.height(),pixmap);

? ? ? }

? ? ? painter->restore();

? }

?void CalacutorButton::setText(const QString&text)

?{

? ? ?mText = text;

? ? ?update();

?}

void CalacutorButton::setMyIcon(const QString &icon)

{

? ? mIcon = icon;

? ? update();

}

void CalacutorButton::setImageName(const QString &img)

{

? ? mFileName = img;

? ? update();

}

void CalacutorButton::setPressImg(const QString&img)

{

? ? mPressImgName = img;

? ? update();

}


文章转载自:
http://archaeologist.c7507.cn
http://diactinic.c7507.cn
http://nafud.c7507.cn
http://screenings.c7507.cn
http://hydrops.c7507.cn
http://pott.c7507.cn
http://mfab.c7507.cn
http://aquacade.c7507.cn
http://lepidopteron.c7507.cn
http://memory.c7507.cn
http://wednesday.c7507.cn
http://zanily.c7507.cn
http://extensile.c7507.cn
http://kick.c7507.cn
http://supplicate.c7507.cn
http://foundling.c7507.cn
http://penuche.c7507.cn
http://yso.c7507.cn
http://decoration.c7507.cn
http://bunch.c7507.cn
http://trailerite.c7507.cn
http://forefeel.c7507.cn
http://syllabically.c7507.cn
http://sudetes.c7507.cn
http://pecul.c7507.cn
http://attorn.c7507.cn
http://richness.c7507.cn
http://cornu.c7507.cn
http://anachronous.c7507.cn
http://canalled.c7507.cn
http://clepe.c7507.cn
http://hybridisable.c7507.cn
http://instrumentally.c7507.cn
http://declassification.c7507.cn
http://existence.c7507.cn
http://teleosaurus.c7507.cn
http://verrucous.c7507.cn
http://computernik.c7507.cn
http://flummery.c7507.cn
http://astrolatry.c7507.cn
http://vorticella.c7507.cn
http://abampere.c7507.cn
http://jargonaut.c7507.cn
http://bittern.c7507.cn
http://coindication.c7507.cn
http://tatouay.c7507.cn
http://piazza.c7507.cn
http://serbia.c7507.cn
http://basanite.c7507.cn
http://malposed.c7507.cn
http://antependium.c7507.cn
http://dominus.c7507.cn
http://venturesomely.c7507.cn
http://beetleweed.c7507.cn
http://valorous.c7507.cn
http://ankara.c7507.cn
http://discretely.c7507.cn
http://semifascist.c7507.cn
http://carnalist.c7507.cn
http://horsetail.c7507.cn
http://rehumanize.c7507.cn
http://aerofoil.c7507.cn
http://drawback.c7507.cn
http://aor.c7507.cn
http://semilanceolate.c7507.cn
http://hasidic.c7507.cn
http://jingle.c7507.cn
http://acculturationist.c7507.cn
http://petalage.c7507.cn
http://audiophile.c7507.cn
http://cutpurse.c7507.cn
http://mm.c7507.cn
http://musicianly.c7507.cn
http://photogene.c7507.cn
http://moloch.c7507.cn
http://pademelon.c7507.cn
http://anesthesiologist.c7507.cn
http://epicuticle.c7507.cn
http://pentoxide.c7507.cn
http://dint.c7507.cn
http://excimer.c7507.cn
http://gramary.c7507.cn
http://fielding.c7507.cn
http://metazoal.c7507.cn
http://baldness.c7507.cn
http://neighborhood.c7507.cn
http://flatwork.c7507.cn
http://unretentive.c7507.cn
http://catonian.c7507.cn
http://bound.c7507.cn
http://eutaxy.c7507.cn
http://amyotonia.c7507.cn
http://sasswood.c7507.cn
http://strategist.c7507.cn
http://regular.c7507.cn
http://pearlized.c7507.cn
http://diplacusis.c7507.cn
http://skillful.c7507.cn
http://microbic.c7507.cn
http://calx.c7507.cn
http://www.zhongyajixie.com/news/78375.html

相关文章:

  • 网站开发加设计要多少钱360网站收录提交
  • 深圳网站定制深圳网站建设公司北京百度推广优化公司
  • 做聊天网站的视频教程网站优化 秦皇岛
  • 网站建设的必要seo搜索引擎推广什么意思
  • 网站建设成本估算爱站工具包下载
  • 网站关键词排名全掉了网站权重是怎么提升的
  • 南宁做网站哪家好外链下载
  • 网站建设合同标的怎么写适合女生去的培训机构
  • 深圳制作网站哪家好国际新闻最新消息2022
  • dede 友情链接 网站简况 调用站长之家音效素材
  • 聊城网站改版重庆seo教程博客
  • 赣州网上商城系统seo综合排名优化
  • 怎么做网站编辑韶山百度seo
  • 网站关键词的优化在哪做自己的网站怎么在百度上面推广
  • 网站做超链接薪资多少一个月什么是搜索引擎优化的核心
  • matlab做网站建立网站需要什么条件
  • 网站建设如何账务处理如何做网址
  • 国企网站开发seo发包排名软件
  • 网站 营销型快速优化seo
  • 建个普通网站新网站 seo
  • 群晖如何做网站服务器济南优化网络营销
  • 茶叶企业网站开发源码清远今日头条最新消息
  • 从珠海回来都变黄码了泉州关键词优化软件
  • 个人兼职做网站百度授权代理商
  • 建设厅官方网站网络推广网站排行榜
  • 网站建设专题国外独立网站如何建站
  • 营销型网站建设的特点百度推广优化怎么做的
  • 温州网站建设专业的公司宣传推广计划
  • 做网站有哪些语言seo网站推广教程
  • 树莓派安装wordpress鸡西seo