PDA

View Full Version : Handling keyPress event such as CTRL+A, CTRL+C on QTableView widgets



gig-raf
10th December 2015, 07:06
Hi All,

I am having some problems implementing the eventFilter for my QTableView (filled with QStandardtems).

This partially works:




....
//ui->playTableView->installEventFilter(this);
}


bool MainWindow::eventFilter(QObject *object, QEvent *e)
{
// Get selected text on keypress event ctrl+e
if (object == ui->playTableView) {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);
if (keyEvent->key() == Qt::Key_A) {
qDebug() << "CTRL-A Key pressed" << keyEvent->key();
return true;
}
}
}
return true;
}


But it makes the app very slow, especially filling the QTableView up with data is like 10 times slower.

What I want to accomplish here is to capture the CTRL-A (Select ALL) keystroke as well as the Arrow Up and Arrow Down when the focus is on the QTableView Widget. I want to keep the default behavior, that all rows in the tableview are selected, but I want to disable some QLineEdits if more than on Row is selected.

If a user selects with the mouse it is not a problem, since I can capture the clicked and double clicked. But How to I catch the CTRL-A ??

Can I use QAction for this?

Hope some one can help me, if possible also with some examples.

Thanks in advace!

Ginsengelf
10th December 2015, 07:30
Hi, I'm not sure if it is related to your speed problem, but you should not return true at the end of the eventFilter function. Returning true means that the event has been filtered. Normally you'd call your base class' implementation of eventFilter to give it the chance to handle events that your class does not handle.

Ginsengelf

gig-raf
10th December 2015, 09:59
Hi!

thanks for your prompt answer. I believe that might have been the reason why my eventFilter was so slow. I changed to false, and no appears to be working appropiately!

Also tried the approach of QAction shotcut. that solution also worked for me for the CTRL+A.

once again Thanks!