Qt 解决用QLineEdit实现的输入框开始没有光标在闪烁的问题

在项目中遇到new出来QLineEdit在开始时,没有光标在闪烁,此时需要重写QlineEdit
代码如下:
.h文件
class CLineEidt : public QLineEdit
{
Q_OBJECT
public:
CLineEidt(QWidget *parent = NULL);
~CLineEidt();
protected:
virtual void focusInEvent(QFocusEvent *e);
virtual void focusOutEvent(QFocusEvent *e);
virtual void showEvent(QShowEvent *event);
private:
signals :
void focusOut(CLineEidt *);
void focusIn(CLineEidt *);
};
.cpp文件
CLineEidt::CLineEidt(QWidget *parent /*= NULL*/) :QLineEdit(parent)
{
}
CLineEidt::~CLineEidt()
{
}
void CLineEidt::focusInEvent(QFocusEvent *e)
{
QLineEdit::focusInEvent(e);
emit focusIn(this);
}
void CLineEidt::focusOutEvent(QFocusEvent *e)
{
QLineEdit::focusOutEvent(e);
emit focusOut(this);
}
void CLineEidt::showEvent(QShowEvent *event)
{
setEnabled(true);
setFocus();
QLineEdit::showEvent(event);
}
调用如下:
CLineEidt *m_filterInputLineEdit = new CLineEidt();
m_filterInputLineEdit->setObjectName("filterInputLineEdit");
m_filterInputLineEdit->setFixedHeight(40);
m_filterInputLineEdit->setMaxLength(60);
m_filterInputLineEdit->setStyleSheet("QLineEdit#filterInputLineEdit{border: 1px solid rgb(224,229,237); }");
//关联槽函数,处理失去焦点与获得焦点的响应函数
connect(m_filterInputLineEdit, SIGNAL(focusOut(CLineEidt*)), this, SLOT(onFoucusOut(CLineEidt*)));
connect(m_filterInputLineEdit, SIGNAL(focusIn(CLineEidt*)), this, SLOT(onFoucusIn(CLineEidt*)));

【Qt 解决用QLineEdit实现的输入框开始没有光标在闪烁的问题】

    推荐阅读