PDA

View Full Version : Is there focus event for line edit?



vjsharma_30
18th February 2010, 19:00
Hi,
I have a form which shows the line edit widget. Now my problem is i want to show the virtual keyboard whenever user clicks on the line edit. Means whenever user highlights it. But i couldn't find any event other than
"textChanged" and "textEdit" . So how to achieve this? Any pointer to the solution will help.

Palmik
18th February 2010, 19:57
I you might be interested in QLineEdit::focusInEvent and QLineEdit::focusOutEvent or QLineEdit::hasFocus

vjsharma_30
18th February 2010, 20:07
I tried this and also installed the event filter

exportData::exportData(QWidget *parent) :
QWidget(parent),
ui(new Ui::exportData)
{
ui->setupUi(this);
ui->edtFileName->installEventFilter(ui->edtFileName);
keyBoard= new KeyboardEntryImpl(ui->edtFileName,NULL);
}

But in the bool exportData::eventFilter(QObject *obj, QEvent *ev)
{
}

I am not able to receive any event.

If i change ui->edtFileName->installEventFilter(ui->edtFileName); to ui->edtFileName->installEventFilter(this);Then i am getting every event that's being generated for the Main window. But i am only intersted in events when Line edit get the focus.

navi1084
19th February 2010, 05:48
ui->edtFileName->installEventFilter(ui->edtFileName);
keyBoard= new KeyboardEntryImpl(ui->edtFileName,NULL);
}

But in the bool exportData::eventFilter(QObject *obj, QEvent *ev)
{
}


You made a mistake here. You have install the event filter of edtFileName to edtFileName. If you want to use event filter in "exportData" class
then you should use function in this way


exportData->installEventFilter(ui->editFileName)


Now your code
bool exportData::eventFilter(QObject *obj, QEvent *ev)
{
}

should work fine :)

Lykurg
19th February 2010, 09:38
You made a mistake here. You have install the event filter of edtFileName to edtFileName. If you want to use event filter in "exportData" class
then you should use function in this way


exportData->installEventFilter(ui->editFileName)


It has to be
installEventFilter(ui->editFileName)

vjsharma_30
19th February 2010, 18:39
It didn't worked either way as mentioned in the upper two replies. But i got it worked just wanted to share that with you guys

I have to call ui->edtFileName->installEventFilter(ui->edtFileName); only because otherwise no event was coming to the event filter if i did

installEventFilter(ui->editFileName) or exportData->installEventFilter(ui->editFileName)
and in event filter i am doing this

bool exportData::eventFilter(QObject *obj, QEvent *ev)
{
if(obj == ui->edtFileName)
{
if(ev->type() == QEvent::MouseButtonPress )
//if(ev->type() == QEvent::FocusIn )
{
keyBoard->show();
ui->edtFileName->setFocus();
}
}
return false;
}

Now i am capturing the mouse press event for the line edit object. But my only worry is that unnes=cessary control comes to this function on every event(apart from line edit events,which i wanted to do).

Lykurg
19th February 2010, 21:12
Yeah, that was too fast. The right syntax should be
ui->edtFileName->installEventFilter(this); in the c-tor of exportData.

Now i am capturing the mouse press event for the line edit object. But my only worry is that unnes=cessary control comes to this function on every event(apart from line edit events,which i wanted to do). That's the sense of an event filter. No problem. You can alternative, instead of returning false, call the base class event handler.