1.重写QLineEdit类,在派生类中重写focusInEvent方法。缺点:输入光标也会消失,需要在重写光标显示。
2.在主窗口增加事件过滤
bool ShortKeySetWidget::eventFilter(QObject *watched, QEvent *event)
{
if (watched->objectName() == "m_lineEdit")
{
if (event->type() == QEvent::FocusIn)
{
this->m_labelTips->setText(tr("press note key"));
}
}
return QWidget::eventFilter(watched, event);
}