现在的位置: 首页 > 综合 > 正文

Qt入门-文本框类QLineEdit和QTextEdit

2014年04月02日 ⁄ 综合 ⁄ 共 975字 ⁄ 字号 评论关闭

    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();

 

抱歉!评论已关闭.