QT——QLineEdit

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;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值