6.3、Qt::TextQlineEdit操作

前言:

本文操作均为在vs2015+QT5.9.5版本中执行

本文重要部分:

**//lineEdit功能设置
//设置提示文字
ui.lineEdit->setPlaceholderText(QString::fromLocal8Bit(“点击pushbutton”));
//设置删除按钮在lineEdit中
ui.lineEdiDelete->setClearButtonEnabled(true);
//设置只读
ui.lineEditRead->setReadOnly(true);
//设置最大长度
ui.lineEditSize->setMaxLength(10);
//lineEdit校验设置
//子网掩码设置
ui.lineEditMask->setInputMask("000.000.000.000; ");
ui.lineEditMask_2->setInputMask("AAAAA; ");
//设置只能输入整数以及浮点型
//整形
QIntValidator *ival = new QIntValidator();
ival->setRange(1, 10000);
ui.lineEditInt->setValidator(ival);
QDoubleValidator dval = new QDoubleValidator();
dval->setRange(0, 10000, 4);
//关闭科学计数法
dval->setNotation(QDoubleValidator::StandardNotation);
ui.lineEditDouble->setValidator(dval);
//正则表达式邮箱验证
QRegExp exp(“[a-zA-Z0-9- ]+@[a-zA-Z0-9- ]+\.[a-zA-Z- ]+”);
QRegExpValidator rval = new QRegExpValidator(exp);
ui.email->setValidator(rval);

** //读取邮箱
ui.label->setText(ui.email->text());
//获取email,进行验证
const QValidator val = ui.email->validator();
/

返回值:
enum State {
Invalid, 格式不正确
Intermediate, 输入中
Acceptable 格式正确
};
/
//设置从头开始
int pos = 0;
//从头开始对比判断格式是否正确,不正确就报错。
if (val->validate(ui.email->text(), pos) != QValidator::Acceptable)
{
ui.label->setText(QString::fromLocal8Bit(“邮箱格式不正确!”));
}
*

头文件:textqlineedit.h

#pragma once

#include <QtWidgets/QWidget>
#include "ui_textqlineedit.h"

class TextQlineEdit : public QWidget
{
   
	Q_OBJECT

public:
	TextQlineEdit(QWidget *parent = Q_NULLPTR);
	public slots:
	void Text();
	void View();
	void Seva();
	void Edit();
	void Return();
	void Edited(QString text);
	void Changed(QString text);
private:
	Ui::TextQlineEditClass ui;
};

UI文件:ui_textqlineedit.h

/********************************************************************************
** Form generated from reading UI file 'textqlineedit.ui'
**
** Created by: Qt User Interface Compiler version 5.9.5
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_TEXTQLINEEDIT_H
#define UI_TEXTQLINEEDIT_H

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_TextQlineEditClass
{
   
public:
    QLineEdit *lineEditInt;
    QLabel *label;
    QLineEdit *lineEditMask;
    QPushButton *pushButton;
    QLabel *label_2;
    QLabel *labelReturn;
    QLineEdit *lineEdit;
    QLineEdit *lineEdiDelete;
    QPushButton *pushButtonSeva;
    QLineEdit *email;
    QPushButton *pushButtonRedo;
    QPushButton *pushButton_2;
    QLineEdit *lineEdit_2;
    QLineEdit *lineEditDouble;
    QLineEdit *lineEditSize;
    QLineEdit *lineEditSignal;
    QPushButton *pushButtonUndo;
    QLineEdit *lineEditMask_2;
    QLabel *labelSignal;
    QLineEdit *lineEditRead;

    void setupUi(QWidget *TextQlineEditClass)
    {
   
        if (TextQlineEditClass->objectName().isEmpty())
            TextQlineEditClass->setObjectName(QStringLiteral("TextQlineEditClass"));
        TextQlineEditClass->resize(970, 714);
        lineEditInt = new QLineEdit(TextQlineEditClass);
        lineEditInt->setObjectName(QStringLiteral("lineEditInt"));
        lineEditInt->setGeometry(QRect(260, 240, 171, 31));
        label = new QLabel(TextQlineEditClass);
        label->setObjectName(QStringLiteral("label"));
        label->setGeometry(QRect(40, 30, 181, 41));
        lineEditMask = new QLineEdit(TextQlineEditClass);
        lineEditMask->setObjectName(QStringLiteral("lineEditMask"));
        lineEditMask->setGeometry(QRect(30, 290, 191, 31));
        QFont font;
        font.setFamily(QStringLiteral("Arial"));
        font.setPointSize(14);
        lineEditMask->setFont(font);
        lineEditMask->setMaxLength(15);
        lineEditMask->setEchoMode(QLineEdit::Normal);
        lineEditMask->setAlignment(Qt::AlignCenter);
        pushButton = new QPushButton(TextQlineEditClass);
        pushButton->setObjectName(QStringLiteral("pushButton"));
        pushButton->setGeometry
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柳一航

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值