QLineEdit (value, assignment, font size color), QTextEdit and QPlainTextEdit in Qt

core:

It’s enough to understand these things. Next time you use it, read the notes and remember it.
(Remember, you can’t memorize it, so let’s give up)

QString

The most commonly used components in interface design are QLabel and QLineEdit;
QLabel is used to display strings, and QLineEdit is used to input and display strings.
Both functions involve the QString class.
The QString class is a frequently used class in Qt programs, which is used to process strings and can convert between strings and numeric values.

QLineEdit

QLineEdit is a single-line text editing control.
A related class of QLineEdit is QTextEdit, which allows multi-line text and rich text editing.

Adjust the size of the LineEdit, the
layout is good,
unlock the layout,
adjust the size

getting information

//获取LineEdit中的值.是QString类型,不能直接用double
QString value = ui->IE_X1_I_2->text();//一般直接用double

//类型转化也是可以的
double value = ui->IE_X1_I_2->text().toDouble();

Assignment

ui->IE_X1_I_2->setText(tr("%1").arg(pso.g_best[0]));

Change background text

   ui->lineEdit->setPlaceholderText("青岛"); 

Set font and size

lineEdit.setFont(QFont( "Timers" , 28 ,  QFont::Bold) );

QTextEdit

Can display multiple rows, used to display images, lists and tables

QTextEdit.setPlainText(str)         #普通文本设定
QTextEdit.insertPlainText(str)      #光标处插入普通文本
QTextEdit.toPlainText()             #普通文本获取

QPlainTextEdit

QPlainTextEdit can be said to be a simplified version of QTextEdit class control.
The one on the left is QTextEdit, and the one on the right is QPlainTextEdit.
QPlainTextEdit replaces the pixel-accurate scrolling method with a line-by-line scrolling method, so it is more efficient (redrawing is required for each scrolling) when processing large batches The text content has a relatively powerful advantage.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43641765/article/details/109564840