Qt入門-文字框類QLineEdit和QTextEdit
阿新 • • 發佈:2019-02-18
QLineEdit是單行文字框。
QTextEdit是多行文字框。
(1)單行文字框QLineEdit
常用的方法和屬性:
(a)獲取和設定文字對齊方式
Qt::Alignment alignment () const
void setAlignment ( Qt::Alignment flag )
(b)獲取和設定檔案框的內容
QString text () const
void setText ( const QString & )
(c)獲取和設定選擇的文字
QString selectedText () const void QLineEdit::setSelection ( int start, int length )
(d)獲取和設定echoMode模式
EchoMode echoMode () const
void 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("12345\nabcdef");
(2)獲取多行文字框的內容:
QString str;
str = textEdt->toPlainText();