如何知道QLineEdit是否得到了关注?

Nar*_*rek 4 c++ qt qlineedit

我希望能够知道QLineEdit它是否是一次点击.所以我想我应该重新实现以下功能(??):

void QLineEdit::focusInEvent ( QFocusEvent * e )   [virtual protected]
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

另外,请告诉我如何使用focusInEvent()函数以了解QLineEdit myEdit;对象是否有焦点.

编辑:我写了以下功能:

bool LoginDialog::eventFilter(QObject *target, QEvent *event)
{
    if (target == m_passwordLineEdit)
    {
        if (event->type() == QEvent::FocusIn)
        {
            if(checkCapsLock())
            {
                QMessageBox::about(this,"Caps Lock", "Your caps lock is ON!");

            }
            return true;

        }
    }
    return QDialog::eventFilter(target, event);
}
Run Code Online (Sandbox Code Playgroud)

m_passwordLineEditLoginDialog类构造函数中注册如下:

m_passwordLineEdit->installEventFilter(this);
Run Code Online (Sandbox Code Playgroud)

它落入了MessageBox-es的无限循环中.请帮我解决这个问题.实际上我想用弹出窗口(不带a QMessageBox)来实现这个功能.是否可以满足QLabel这种需求?

And*_*y M 6

另外,请告诉我如何使用focusInEvent()函数以了解QLineEdit myEdit; 对象得到了重点.

您应该将自己连接到以下SIGNAL:

void QApplication::focusChanged ( QWidget * old, QWidget * now )   [signal]
Run Code Online (Sandbox Code Playgroud)

当新的QWidget是您的QLineEdit时,您知道它得到了关注!

希望能帮助到你 !