在QLineEdit子类中未调用focusInEvent

focusInEvent not called in QLineEdit subclass

本文关键字:调用 focusInEvent QLineEdit 子类      更新时间:2023-10-16

我有一个Qt/cpp代码,并显示子类QLineEdit。当双击QLineEdit时,focusInEvent永远不会被调用(在Maya中启动)。

void myQLineEditClass::focusInEvent(QFocusEvent *e)
{
    MGlobal::displayInfo(MQtUtil::toMString(QString().sprintf("HERE")));
    QLineEdit::focusInEvent(e);
}
如果focusInEvent存在于.h保护部分,则永远不会显示

HERE。你知道如何获得focusInEvents吗?

尝试以下操作。有几次,当focusInEvent不起作用时,它对我有效。

void YourWidget::changeEvent(QEvent* event)
{
    if (event->type() == QEvent::ActivationChange)
    {
        if (isActiveWindow())
        {
             // gaining the focus
        }
        else
        {
             // loosing the focus
        }
    }
    // or whatever *parent* class call is
    QWidget::changeEvent(event);
}

事件被编辑器小部件截获。参见QItemDelegate::createEditor。返回的小部件将获得它。

该问题与QLineEdit位于另一个QGraphicsView中的QGraphicsView中的事实相关联。将QLineEdit带到更高级别的QGraphicsView使其工作