QLineEdit是单行文本框。
QTextEdit是多行文本框。
(1)单行文本框QLineEdit
常用的方法和属性:
(a)获取和设置文本对齐方式
Qt::Alignment alignment () const
void setAlignment ( Qt::Alignment flag )
(b)获取和设置文件框的内容
(c)获取和设置选择的文本
QString selectedText () constvoid QLineEdit::setSelection ( int start, int length )(d)获取和设置echoMode模式
EchoMode echoMode () constvoid setEchoMode ( EchoMode )echoMode模式的值可以是:
QLineEdit::Normal 0 Display characters as they are entered. This is the default.QLineEdit::NoEcho 1 Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.QLineEdit::Password 2 Display asterisks instead of the characters actually entered.QLineEdit::PasswordEchoOnEdit 3 Display characters as they are entered while editing otherwise display asterisks.(2)多行文本框QTextEdit
QTextEdit显示多行文本内容,当文本内容超出控件显示范围时,可以显示水平和垂直滚动条。
通过设置acceptRichText属性,QTextEdit不仅可以显示文字,还可以显示HTML文档、图像、表格等元素。
示例:
(1)设置多行文本框的内容:
textEdt->setPlainText("12345nabcdef");
(2)获取多行文本框的内容:
QString str;
str = textEdt->toPlainText();
本文属转载
原文:https://blog.csdn.net/xgbing/article/details/7766476