PDA

View Full Version : focusInEvent not call for QLineEdit



EarthHobbit
20th May 2015, 22:28
Hi,
I have a subclassed QLineEdit added to a GraphicsScene and a focusInEvent associated to it.
However the focusInEvent is never called. I tried adding an event filter, but without success.
.h

class myQLineEditClass : public QLineEdit
{
Q_OBJECT
public:
myQLineEditClass();
virtual ~myQLineEditClass() {};

protected:
void focusInEvent(QFocusEvent *e);
void focusOutEvent(QFocusEvent *e);
bool eventFilter(QObject *obj, QEvent *event);
};

.cpp:

bool myQLineEditClass::eventFilter(QObject *obj, QEvent *event)
{
MGlobal::displayInfo(MQtUtil::toMString(QString(). sprintf("EVENT FILTER")));

if (event->type() == QEvent::FocusIn)
{
return true;
}

return QObject::eventFilter(obj, event);
}
void myQLineEditClass::focusInEvent(QFocusEvent *e)
{
MGlobal::displayInfo(MQtUtil::toMString(QString(). sprintf("FOCUS IN")));
QLineEdit::focusInEvent(e);
}

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

/.../
myQLineEditClass *qledit=new myQLineEditClass(oneNode);
scene()->addWidget(qledit);
qledit->installEventFilter(oneNode);


However neither EVENT FILTER, nor FOCUS IN, nor FOCUS OUT are ever called with I double-click on the QLineEdit. How come ?
Thanks.