void setGeometry(int x, int y, int w, int h)
void setGeometry(const QRect &) //属性:位置、大小
void setFocusPolicy(Qt::FocusPolicy policy) //属性:获取焦点
void setStyleSheet(const QString & styleSheet) //属性:样式表
void setText(const QString &)
==============================================================
This signal is emitted when the Return or Enter key is pressed.
当Return或者Enter键被按下时,信号将被发射。
void QLineEdit::returnPressed() [signal]
-------------------------------------------------------------
void QLineEdit::editingFinished() [signal]
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus.
==============================================================
键盘焦点事件(虚函数,继承自 QWidget::focusOutEvent())
void QLineEdit::focusInEvent(QFocusEvent * e) [virtual protected] //获取焦点事件
void QLineEdit::focusOutEvent(QFocusEvent * e) [virtual protected]//失去焦点事件
==============================================================
效果:
My_LineEdit::My_LineEdit(QWidget *parent): QLineEdit(parent)
{
this->setGeometry(QRect(150,250,150,20));
this->setFocusPolicy(Qt::ClickFocus);
this->setStyleSheet( QStringLiteral("color: rgb(150, 150, 150);") );
this->setText("< Please Enter The End >");
}
My_LineEdit::~My_LineEdit()
{
}
void My_LineEdit::focusInEvent(QFocusEvent *e)
{
if( Focus_Flag )
{
this->clear();
this->setStyleSheet( QStringLiteral("color: rgb(0, 0, 0);") );
Focus_Flag = false;
}
}
void My_LineEdit::focusOutEvent(QFocusEvent *e)
{
this->setStyleSheet( QStringLiteral("color: rgb(150, 150, 150);") );
this->setText("< Please Enter The End >");
Focus_Flag = true;
}