Qt组件之文本框类

来源:互联网 发布:php判断时间范围 编辑:程序博客网 时间:2024/06/06 03:07

QLineEdit:单行文本框
QTextEdit:多行文本框
若组件是通过拖拽生成的,那么可以使用ui.lineEdit->setText(str);

一、 QLineEdit

常用方法:
(1) 获取和设置文本对齐方式

Qt::Alignment   alignment () constvoid    setAlignment ( Qt::Alignment flag )

(2) 获取和设置文本框内容

QString text () constvoid    setText ( const QString & )

(3) 获取和设置选择的文本

QString selectedText () constvoid QLineEdit::setSelection ( int start, int length )

(4) 获取和设置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.

二、 QTextEdit

可以显示多行文本内容,当文本内容超出组件显示的范围的时候,可以显示水平和垂直滚动条。通过设置acceptRichText属性,不仅可以显示文字,还可以显示HTML文档、图像、表格等元素。
(1) 设置多行文本框内容

textEdt->setPlainText("12345\nabcdef");

(2) 获取多行文本框内容

QString str;str = textEdt->toPlainText();
0 0