Qt入门-文本框类QLineEdit和QTextEdit

转自http://blog.csdn.net/xgbing/article/details/7766476
分类: [Qt+VS2008]   9111人阅读  评论(0)  收藏  举报

    QLineEdit是单行文本框。

    QTextEdit是多行文本框。


 

 

(1)单行文本框QLineEdit

常用的方法和属性:

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

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

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

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

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

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

  (d)获取和设置echoMode模式

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

echoMode模式的值可以是:

[plain]  view plain copy
  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 plain copy
  1. textEdt->setPlainText("12345\nabcdef");  


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

[cpp]  view plain copy
  1. QString str;  
  2. str = textEdt->toPlainText(); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值