#include "widget.h"
#include <QLineEdit>
#include <QVBoxLayout>
#include <QString>
#include <QAction>
#include <QRegExp>
#include <QIntValidator>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QLineEdit *pNormalLineEdit = new QLineEdit(this);
QLineEdit *pNoEchoLineEdit = new QLineEdit(this);
QLineEdit *pPasswordLineEdit = new QLineEdit(this);
QLineEdit *pPasswordEchoOnEditLineEdit = new QLineEdit(this);
pNormalLineEdit->setPlaceholderText("Normal");
pNoEchoLineEdit->setPlaceholderText("NoEcho");
pPasswordLineEdit->setPlaceholderText("Password");
pPasswordEchoOnEditLineEdit->setPlaceholderText("PasswordEchoOnEditLineEdit");
// 设置显示效果
pNormalLineEdit->setEchoMode(QLineEdit::Normal);
pNoEchoLineEdit->setEchoMode(QLineEdit::NoEcho);
pPasswordLineEdit->setEchoMode(QLineEdit::Password);
pPasswordEchoOnEditLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
//*************************************
m_pLineEdit = new QLineEdit(this);
m_pLabel = new QLabel(this);
m_pLineEdit->setPlaceholderText(QString::fromLocal8Bit("请输入搜索内容"));
m_pLabel->setText(QString::fromLocal8Bit("输入内容为:"));
QAction *pLeadingAction = new QAction(this);
pLeadingAction->setIcon(QIcon("D:/qt/LineEdit/2.png"));
m_pLineEdit->addAction(pLeadingAction, QLineEdit::LeadingPosition);
QAction *pTrailingAction = new QAction(this);
pTrailingAction->setIcon(QIcon("D:/qt/LineEdit/1.ico"));
m_pLineEdit->addAction(pTrailingAction, QLineEdit::TrailingPosition);
// 连接信号和槽
connect(pTrailingAction, SIGNAL(triggered(bool)), this, SLOT(onSearch(bool)));
//**************************************
//**************************************
QLineEdit *pIntLineEdit = new QLineEdit(this);
QLineEdit *pDoubleLineEdit = new QLineEdit(this);
QLineEdit *pValidatorLineEdit = new QLineEdit(this);
pIntLineEdit->setPlaceholderText(QString::fromLocal8Bit("整形"));
pDoubleLineEdit->setPlaceholderText(QString::fromLocal8Bit("浮点型"));
pValidatorLineEdit->setPlaceholderText(QString::fromLocal8Bit("字母和数字"));
// 整形 范围:[1, 99]
QIntValidator *pIntValidator = new QIntValidator(this);
pIntValidator->setRange(1, 99);
// 浮点型 范围:[-360, 360] 精度:小数点后2位
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pDoubleValidator->setRange(-360, 360);
pDoubleValidator->setNotation(QDoubleValidator::StandardNotation);
pDoubleValidator->setDecimals(2);
// 字符和数字
QRegExp reg("[a-zA-Z0-9]+$");
QRegExpValidator *pValidator = new QRegExpValidator(this);
pValidator->setRegExp(reg);
pIntLineEdit->setValidator(pIntValidator);
pDoubleLineEdit->setValidator(pDoubleValidator);
pValidatorLineEdit->setValidator(pValidator);
//************************************
//************************************
QLineEdit *pIPLineEdit = new QLineEdit(this);
QLineEdit *pMACLineEdit = new QLineEdit(this);
QLineEdit *pDateLineEdit = new QLineEdit(this);
QLineEdit *pLicenseLineEdit = new QLineEdit(this);
pIPLineEdit->setInputMask("000.000.000.000;_");
pMACLineEdit->setInputMask("HH:HH:HH:HH:HH:HH;_");
pDateLineEdit->setInputMask("0000-00-00");
pLicenseLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
//************************************
QVBoxLayout *gLayout = new QVBoxLayout(this);
gLayout->addWidget(pNormalLineEdit,0,0);
gLayout->addWidget(pNoEchoLineEdit,1,0);
gLayout->addWidget(pPasswordLineEdit,2,0);
gLayout->addWidget(pPasswordEchoOnEditLineEdit,3,0);
gLayout->addWidget(m_pLineEdit,4,0);
gLayout->addWidget(m_pLabel,5,0);
gLayout->addWidget(pIntLineEdit,6,0);
gLayout->addWidget(pDoubleLineEdit,7,0);
gLayout->addWidget(pValidatorLineEdit,8,0);
gLayout->addWidget(pIPLineEdit,9,0);
gLayout->addWidget(pMACLineEdit,10,0);
gLayout->addWidget(pDateLineEdit,11,0);
gLayout->addWidget(pLicenseLineEdit,12,0);
this->setLayout(gLayout);
}
Widget::~Widget()
{
}
void Widget::onSearch(bool checked)
{
QString strText = m_pLineEdit->text();
m_pLabel->setText(QString::fromLocal8Bit("输入内容为:%1").arg(strText));
}
Qt:QLineEdit
4星 · 超过85%的资源 需积分: 49 28 浏览量
2016-08-06
18:09:58
上传
评论 1
收藏 13KB ZIP 举报
好儿郎-志在四方
- 粉丝: 2210
- 资源: 32
最新资源
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
- 基于单片机的风力发电机转速控制源码
- 基于C++实现的风力发电气动平衡监测系统+源代码+测量数据(高分课程设计)
- 毕业设计- 基于STM32F103C8T6 单片机,物联网技术的太阳能发电装置+源代码+文档说明+架构图+界面截图
- 基于 LSTM(长短期记忆)(即改进的循环神经网络)预测风力发电厂中风力涡轮机产生的功率+源代码+文档说明
- 基于stm32f103+空心杯电机+oled按键+运动算法
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈