当前位置:网站首页>QT qlineedit, qtextedit, qplaintextedit differences
QT qlineedit, qtextedit, qplaintextedit differences
2022-07-28 14:52:00 【Love the west wind】
QLineEdit、QTextEdit 、QPlainTextEdit Respective use scenarios
QLineEdit
QLineEdit It's a single line text input box .
QLineEdit Allows users to enter and edit single line plain text , Provides a lot of useful editing functions , Include : Undo and Redo 、 Cut and paste 、 And drag and drop ( see setDragEnabled()).
By changing the echoMode(), It can also be set as a “ Just write ” Field , Used to enter passwords, etc .
// Limit maximum input 128 position
lineEdit->setMaxLength(128);
// Not writable
lineEdit->setEchoMode(QLineEdit::NoEcho);
// password * Number input
lineEdit->setEchoMode(QLineEdit::Password);Varied echoMode()
switch (index) {
case 0:
// Default , What you enter is displayed
echoLineEdit->setEchoMode(QLineEdit::Normal);
break;
case 1:
// password , Generally, small black dots are used to cover the characters you enter
echoLineEdit->setEchoMode(QLineEdit::Password);
break;
case 2:
// When editing, input characters to display the input content , Otherwise, use small black dots instead
echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
break;
case 3:
// No input is visible ( Just can't see , It's not that you can't input )
echoLineEdit->setEchoMode(QLineEdit::NoEcho);
}LineEdit Edit box limits number input collation
// Display the integer of the specified range
ui->lineEdit->setValidator(new QIntValidator(1,1000,this)); // [1,1000] Integer input in the range
ui->lineEdit->setValidator(new QDoubleValidator(0.1,0.9,2,this)); // [0.1,0.9], After the decimal point 2 position
ui->lineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[(\\s|\\S)+]{0,200}$"),this)); // Input 200 Characters
// Just enter the numbers , Decimal point and minus sign
QRegExp exp("[0-9\\.-]+$");
QValidator *Validator = new QRegExpValidator(exp);
ui->lineEdit->setValidator(Validator);
//ip Address input
QString exp = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
"(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
QRegExp rege(exp);
QValidator *Validator = new QRegExpValidator(rege);
ui->lineEdit->setValidator(Validator);You can only enter Numbers
// Integers
QRegExp exp("^-?[0-9]+$");
QValidator *Validator = new QRegExpValidator(exp);
ui->lineEdit_PageIndexList->setValidator(Validator);data
// The set of real Numbers
QRegExp exp("^-?[0-9\\.]+$");
QValidator *Validator = new QRegExpValidator(exp);
ui->lineEdit->setValidator(Validator);
// Positive integer
QRegExp exp("^0?[.]\\d+$");
QValidator *Validator = new QRegExpValidator(exp);
ui->lineEdit->setValidator(Validator);
// Positive decimal
QRegExp exp("^[1-9]\\d+$");
QValidator *Validator = new QRegExpValidator(exp);
ui->lineEdit->setValidator(Validator);QTextEdit
Multiple lines , Rich text editor , It can also be displayed HTML Rich text ;
QTextEdit* m_textShower;// The text that reads the contents of the file is displayed
m_textShower = newQTextEdit;
(1) How to set the font
QFonttextFont;
textFont.setPointSize(16);
m_textShower->setFont(textFont);
(2) Set the method of editing as read-only property
m_textShower->setReadOnly(true);
(3) How to set text
QTextCursorcsor = m_textShower->textCursor();
csor.movePosition(QTextCursor::Start);
csor.insertText(fileContext);
(4) How to clear text
m_textShower->clear();Text can use setSelection() or selectAll() To select , The selected text can be cut()、copy() and paste(), Use setAlignment() To set the alignment of text .
Very powerful ;
QPlainTextEdit
QPlainTextEdit Is a multiline text editor , For displaying and editing multiple lines of simple text .
QPlainTextEdit It can be understood as QTextEdit Low profile version of .QPlainTextEdit Support plain text display ,QTextEdit Support rich text display . One more style .
QPlainTextEdit The displayed efficiency ratio QTextEdit high , If you need to display a lot of text , Especially when you need the scroll bar to scroll back and forth ,QPlainTextEdit Is much better .
Common methods
// Append a line of string
appendPlainText()
// take QPlainTextEdit The text in the component is converted to a string
toPlainText()
// Reading strings line by line is troublesome ,QPlainTextEidt With QTextDocument Type stores data
document() Member functions , You can return the file object pointer QTextDocument
// Is a text object in memory , Store in text blocks , Judge the text block with carriage return , That is to say, generally one line is a text block
QTextDocument
//QTextDocument Member function of , Read text block , The serial number from 0 Start , The read text block is QTextBlock type , You can go through text() Member function gets text QString
findBlockByNumber(int)
// Member functions , Can get QTextDocument Number of text blocks , Used to traverse text blocks
blockCount()
边栏推荐
- (function(global,factory){
- Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
- 35道MySQL面试必问题图解,这样也太好理解了吧
- How to effectively conduct the review meeting (Part 1)?
- The 35 required questions in MySQL interview are illustrated, which is too easy to understand
- 围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
- OKR与GRAD
- [ecmascript6] modularization
- C语言库函数getchar()怎么使用
- Getting started with scottplot tutorial: getting and displaying values at the mouse
猜你喜欢

ssh服务
Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新

How to use the C language library function getchar ()

看了就会的 Rainbond 入门教程

多商户商城系统功能拆解17讲-平台端订单列表

How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally

OKR and grad

ScottPlot入门教程:获取和显示鼠标处的数值

On July 29, apachecon | apachepulsar's exploration and practice in vivo will be broadcast soon

7月29日 ApacheCon|Apache Pulsar 在 vivo 的探索与实践 即将开播
随机推荐
It's so hot that solar power can't take off? Hello, head
Thoughts on the construction of some enterprise data platforms
Several methods of opening URL in swiftui view
Hcip day 10
用 Table 在 SwiftUI 下创建表格
如何只降3D相机不降UI相机的分辨率
Redis-持久化
Some problems encountered in the development of Excel VBA, solutions, and continuous updates
Core Data 是如何在 SQLite 中保存数据的
Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance
[ecmascript6] async and await
QT qbuttongroup realizes single selection and multiple selection
Swiftui layout - size (bottom)
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
C language: mathematical method of converting decimal system into binary system
实时切换 Core Data 的云同步状态
Hcip day 11
C language related programming exercises
Simple data analysis using Weka and excel
OKR与GRAD