Qt入门-文本框类QLineEdit和QTextEdit

来源:互联网 发布:java base64 json传递 编辑:程序博客网 时间:2024/05/17 23:50
转自http://blog.csdn.net/xgbing/article/details/7766476
分类: [Qt+VS2008] 9111人阅读 评论(0) 收藏 举报
qtpasswordsalignmenthtml文档c

    QLineEdit是单行文本框。

    QTextEdit是多行文本框。


 

 

(1)单行文本框QLineEdit

常用的方法和属性:

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

[cpp] view plaincopy
  1. Qt::Alignment   alignment () const  
  2. void    setAlignment ( Qt::Alignment flag )  

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

[cpp] view plaincopy
  1. QString text () const  
  2. void    setText ( const QString & )  

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

[cpp] view plaincopy
  1. QString selectedText () const  
  2. void QLineEdit::setSelection ( int start, int length )  

  (d)获取和设置echoMode模式

[cpp] view plaincopy
  1. EchoMode    echoMode () const  
  2. void    setEchoMode ( EchoMode )  

echoMode模式的值可以是:

[plain] view plaincopy
  1. QLineEdit::Normal   0   Display characters as they are entered. This is the default.  
  2. QLineEdit::NoEcho   1   Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.  
  3. QLineEdit::Password 2   Display asterisks instead of the characters actually entered.  
  4. QLineEdit::PasswordEchoOnEdit   3   Display characters as they are entered while editing otherwise display asterisks.  


(2)多行文本框QTextEdit
   QTextEdit显示多行文本内容,当文本内容超出控件显示范围时,可以显示水平和垂直滚动条。

  通过设置acceptRichText属性,QTextEdit不仅可以显示文字,还可以显示HTML文档、图像、表格等元素。

 

示例:

(1)设置多行文本框的内容:

[cpp] view plaincopy
  1. textEdt->setPlainText("12345\nabcdef");  


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

[cpp] view plaincopy
  1. QString str;  
  2. str = textEdt->toPlainText(); 
0 0
原创粉丝点击