QTextEdit的使用(限制输入的字符数的个数,包括纯中文输入或自由输入)

QTextEdit使用

#限制QTextEdit的字符数的最大输入量,包括中文字符数或自由字符的最大输入量(纯中文输入、自由字符输入)

##UI界面效果图
在这里插入图片描述
##textEdit.h

#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include <QMainWindow>

namespace Ui {
class textEdit;
}

class textEdit : public QMainWindow
{
    Q_OBJECT

public:
    explicit textEdit(QWidget *parent = 0);
    ~textEdit();

private slots:
    void EmailTypeChanged(int index);
    void FastCheckBoxClicked();
    void InputTextChanged();


private:
    Ui::textEdit *ui;
    int m_iFastMaxLength_free;
    int m_iNormalMaxLength_free;
    int m_iFastMaxLength_chinese;
    int m_iNormalMaxLength_chinese;

    bool IsChinese(ushort usUnicode);
    void CountNumber();
    void CheckFreeEmail();
    void CheckChineseEmail();
    QString GetChineseFromContent(QString qstrContent);
};

#endif // TEXTEDIT_H

##textEdit.cpp

#include "textedit.h"
#include "ui_textedit.h"
#include "qtextcursor.h"
#include "qmessagebox.h"

textEdit::textEdit(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::textEdit)
{
    ui->setupUi(this);
    m_iFastMaxLength_free = 16;
    m_iNormalMaxLength_free = 30;
    m_iFastMaxLength_chinese = 10;
    m_iNormalMaxLength_chinese = 20;

    connect(ui->fast_checkBox, SIGNAL(clicked(bool)), this, SLOT(FastCheckBoxClicked()));
    connect(ui->emailType_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(EmailTypeChanged(int)));
    connect(ui->content_textEdit, SIGNAL(textChanged()), this, SLOT(InputTextChanged()));
}


textEdit::~textEdit()
{
    delete ui;
}


void textEdit::InputTextChanged()
{
    int index = ui->emailType_comboBox->currentIndex();
    if(0 == index)
    {
        CheckFreeEmail();
    }
    else
    {
        CheckChineseEmail();
    }

    CountNumber();
}


void textEdit::EmailTypeChanged(int index)
{
    QString qstrContent = ui->content_text
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值