PDA

View Full Version : prob in filter Esc key for dialog in a class



Askar
11th December 2009, 10:54
This is my code


void CommonFunctions::progressbar(QString Dialogtext)
{
layout = new QVBoxLayout;
l = new QLabel( Dialogtext);
l->setWordWrap(true);
progress = new QProgressBar();
progress->setWindowModality(Qt::WindowModal);
progress->setRange(0,10);
layout->addWidget(l);
layout->addWidget(progress,Qt::AlignCenter);
win->setMaximumWidth(320);
win->setModal(true);
win->setLayout(layout);
win->setWindowTitle("title");
installEventFilter(win);
win->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButton Hint);
win->show();
}

bool QDialog::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Escape) {
keyEvent->ignore();
return true;
} else
return false;
}
return false;
}

i had checked this code by setting a breakpoint in eventFilter(), while pressing Esc key debugger stops at break point and checks the condition in 22 line of the above code , but it fails & returns false

where im getting wrong can anybody help me....

high_flyer
11th December 2009, 10:59
EDIT:
events of which object do you want to filter?

wagmare
11th December 2009, 11:44
try this ... but not sure
win->installEventFilter(this);
bool CommonFunctions::eventFilter()

Askar
11th December 2009, 14:12
i already tried with
bool CommonFunctions::eventFilter()
but it gives error eventFilter() not a member of CommonFunctions

high_flyer
14th December 2009, 15:18
you have to add it to your header too!

faldzip
14th December 2009, 16:11
i already tried with
bool CommonFunctions::eventFilter()
but it gives error eventFilter() not a member of CommonFunctions

I think you should start from the beginning and learn some necessary C++ basics...