PDA

View Full Version : Qline edit focusIn event



deepal_de
9th June 2011, 06:39
hello
How can i catch a QlineEdit focusIn event from the main window..
without subclassing QlineEdit ...

Santosh Reddy
9th June 2011, 07:44
You can create and install an event filter, and emit a signal in there, something like this


class FocusInSignal: public QObject
{
Q_OBJECT
...
signals:
void focusIn(void);

protected:
bool FocusInSignal::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::FocusIn) {
emit focusIn();
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
}
}

// in the main window
FocusInSignal* filter = new filter(this);
connect(filter, SIGNAL(focusIn()), this, SLOT(lineEditGotFucus()));
lineEdit->installFilter(filter);

void MainWindow::lineEditGotFucus(void)
{
// processes
}