gemidjy
19th February 2008, 14:07
Hello, I am having an issue with QTableView object that I use in my application. I implement the keyPressEvent(QKeyEvent *event) method to get the event when a key is pressed. Thus, I want to get findout when the Enter/Return key is pressed while the application's focus is in the QTableView object. So I do:
void jeamMain::keyPressEvent(QKeyEvent *e)
{
switch(e->key()) {
case Qt::Key_Return:
if(jeamTableView->hasFocus())
QMessageBox::information(this, "", "Enter pressed and focus on table");
else
return;
break;
}
}
But the QTableView object (jeamTableView) seems that it doesn't accept events from the keyboard. It's like ignoring the Return key. If I remove the "if" construction that checks if the focus is in the jeamTableView object, and put the focus in QLineEdit object and press Return, I get the QMessageBox with the text "Enter pressed and focus on table". Otherwise, jeamTableView doesn't react on the keyPressEvent.
The focus policy set for the jeamTableView is StrongFocus.
Thanks in advance
void jeamMain::keyPressEvent(QKeyEvent *e)
{
switch(e->key()) {
case Qt::Key_Return:
if(jeamTableView->hasFocus())
QMessageBox::information(this, "", "Enter pressed and focus on table");
else
return;
break;
}
}
But the QTableView object (jeamTableView) seems that it doesn't accept events from the keyboard. It's like ignoring the Return key. If I remove the "if" construction that checks if the focus is in the jeamTableView object, and put the focus in QLineEdit object and press Return, I get the QMessageBox with the text "Enter pressed and focus on table". Otherwise, jeamTableView doesn't react on the keyPressEvent.
The focus policy set for the jeamTableView is StrongFocus.
Thanks in advance