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...
{
bool bRetVal = false;
if (event
->type
() == QEvent::FocusIn) { QLineEdit *grid
= static_cast<QLineEdit
*>
(obj
);
if (grid->text().isEmpty()){
if (bTurnChk) {
grid->setText("X");
bTurnChk = false;
}
else {
grid->setText("O");
bTurnChk = true;
}
}
}
return bRetVal;
}
bool QGridEventHandler::eventFilter(QObject *obj, QEvent *event)
{
bool bRetVal = false;
if (event->type() == QEvent::FocusIn) {
QLineEdit *grid = static_cast<QLineEdit *> (obj);
if (grid->text().isEmpty()){
if (bTurnChk) {
grid->setText("X");
bTurnChk = false;
}
else {
grid->setText("O");
bTurnChk = true;
}
}
}
return bRetVal;
}
To copy to clipboard, switch view to plain text mode
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...
{
bool bRetVal = true;
if (event
->type
() == QEvent::FocusIn) { QLineEdit *grid
= static_cast<QLineEdit
*>
(obj
);
if (grid->text().isEmpty()){
if (bTurnChk) {
grid->setText("X");
bTurnChk = false;
}
else {
grid->setText("O");
bTurnChk = true;
}
}
}
else {
bRetVal
= QObject::eventFilter(obj, event
);
}
return bRetVal;
}
bool QGridEventHandler::eventFilter(QObject *obj, QEvent *event)
{
bool bRetVal = true;
if (event->type() == QEvent::FocusIn) {
QLineEdit *grid = static_cast<QLineEdit *> (obj);
if (grid->text().isEmpty()){
if (bTurnChk) {
grid->setText("X");
bTurnChk = false;
}
else {
grid->setText("O");
bTurnChk = true;
}
}
}
else {
bRetVal = QObject::eventFilter(obj, event);
}
return bRetVal;
}
To copy to clipboard, switch view to plain text mode
Thanks for your patience
Bookmarks