Laurent Crivello
Laurent Crivello

Reputation: 3931

focusInEvent not called in QLineEdit subclass

I have a Qt/cpp code and display a subclassed QLineEdit. When double-clicking the QLineEdit, the focusInEvent is never called (launched in Maya).

void myQLineEditClass::focusInEvent(QFocusEvent *e)
{
    MGlobal::displayInfo(MQtUtil::toMString(QString().sprintf("HERE")));
    QLineEdit::focusInEvent(e);
}

HERE is never displayed, event if the focusInEvent is present in the .h protect part. Any idea how to get focusInEvents ?

Upvotes: 0

Views: 883

Answers (3)

Laurent Crivello
Laurent Crivello

Reputation: 3931

The issue was linked to the fact that the QLineEdit was in a QGraphicsView that was in another QGraphicsView. Bringing the QLineEdit to the higher-level QGraphicsView made it work.

Upvotes: 1

fassl
fassl

Reputation: 754

The event gets intercepted by the editor widget. See QItemDelegate::createEditor. The widget returned there will get it.

Upvotes: 1

Alexander V
Alexander V

Reputation: 8698

Try the below. For several occasions that worked for me when focusInEvent did not.

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

Upvotes: 1

Related Questions