Qt 文本框类QLineEdit和QTextEdit

xiaoxiao2021-02-28  109

转载地址:http://blog.csdn.net/xgbing/article/details/7766476

QLineEdit是单行文本框。

QTextEdit是多行文本框。

 

 

(1)单行文本框QLineEdit

常用的方法和属性:

  (a)获取和设置文本对齐方式

[cpp]  view plain  copy Qt::Alignment   alignment () const   void    setAlignment ( Qt::Alignment flag )  

  (b)获取和设置文件框的内容

[cpp]  view plain  copy QString text () const   void    setText ( const QString & )  

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

[cpp]  view plain  copy QString selectedText () const   void QLineEdit::setSelection ( int start, int length )  

  (d)获取和设置echoMode模式

[cpp]  view plain  copy EchoMode    echoMode () const   void    setEchoMode ( EchoMode )  

echoMode模式的值可以是:

[plain]  view plain  copy 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)设置多行文本框的内容:

[cpp]  view plain  copy textEdt->setPlainText("12345\nabcdef");  

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

[cpp]  view plain  copy QString str;   str = textEdt->toPlainText();  
转载请注明原文地址: https://www.6miu.com/read-52393.html

最新回复(0)