I want to do something to an QLineEdit when the user clicks on it. It looks like I need to capture the QLineEdit::focusInEvent(). I do NOT want to have to spin my own, is there some way to capture the event in the container dialog?
Printable View
I want to do something to an QLineEdit when the user clicks on it. It looks like I need to capture the QLineEdit::focusInEvent(). I do NOT want to have to spin my own, is there some way to capture the event in the container dialog?
Install an event filter on your dialog: QObject::installEventFilter(). There you can catch the focus event of your line edit.
Hi,
I am a newbie to Qt programming. I was able to successfully install event filters on my objects when I coded the ui myself. I then decided to use Qt Designer to construct my UI but I am unable to figure out how event filters get installed on ui objects constructed using the designer. How do I installEventFilter using QtDesigner?
Thanks,
Priya
e.g.:right in the constructor.Code:
ui->NameOfYourWidget->installEventFilter(this);
Hi Lykurg,
Thank you for the quick response. I did try installing the event filter using the method you suggested
ui->NameOfYourWidget->installEventFilter(this); but when I run the application, the two QLineEdit boxes to which I have installed the event filter show up blank. Is there a way to debug this ?
Thanks again for you time,
Priya
Hi Lykurg,
I managed to debug it myself. For some reason when I set the return value to false in the eventFilter function, the objects show up. Wonder if I am missing something..
Here is my eventFilter function...
Code:
{ bool bRetVal = false; if (grid->text().isEmpty()){ if (bTurnChk) { grid->setText("X"); bTurnChk = false; } else { grid->setText("O"); bTurnChk = true; } } } return bRetVal; }
Thanks,
Priya
I guess I should try myself before asking :) I just realized other events get triggered before the launch of the application, which need to be processed in the default manner. This happens only when the custom eventFilter function returns false if the QLineEdit's event is not processed or when the QObject's eventFilter function is called from within..
I have changed the code to the following and this works now...
Thanks for your patienceCode:
{ bool bRetVal = true; if (grid->text().isEmpty()){ if (bTurnChk) { grid->setText("X"); bTurnChk = false; } else { grid->setText("O"); bTurnChk = true; } } } else { } return bRetVal; }
Well, I guess then your event filter is the problem. What do you want to achieve and how does your event filter look like?