Qt:常用控件QLineEdit

QLineEdit是单行文本编辑控件。比如用户名,密码等输入框可以使用该控件。

所属头文件

常用方法

1.void setText(const QString &)

  设置编辑框文本内容

2.void setReadOnly(bool)

  控件设置为只读模式

3.void setPlaceholderText(const QString &)

  设置编辑框中的默认提示信息

4.void setMaxLength(int)

  设置编辑中输入的最大长度

5.void setEchoMode(EchoMode)

  设置编辑框的输入模式

  QLineEdit::Normal:默认模式,输入与现实一致

  QLineEdit::Password:密码模式,输入的内容用黑点代替,无法看到输入的内容  
  

  QLineEdit::PasswordEchoOnEdit:编辑时内容可现实,否则为密码模式

  QLineEdit::NoEcho:输入不可见

6.void setAlignment(Qt::Alignment flag)

  设置文本显示位置

  Qt::AlignLeft:文本在左侧

  Qt::AlignCenter:文本在居中

  Qt::AlignRight:文本在右侧

7.void setClearButtonEnabled(bool enable)

  添加清楚按钮

  显示效果为:
  

8.void QLineEdit::setValidator(const QValidator *v)

  对输入的内容进行限制

  setValidator(0):无限制

  setValidator(new QIntValidator(this)):只能输入整数

常用信号

1.void textChanged(const QString &text)

  文本变化时发出信号

2.void returnPressed();

  光标在输入框,按回车键发出信号

 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×