PDA

View Full Version : Help with a QTableView event



waynew
2nd May 2010, 17:24
I need to add some custom action when the user presses the Enter key while the QTableView has focus, like when the user saves a cell edit.

Don't think a shortcut is good because the normal key behavior will get overridden.

I can see an event function in the inherited members list for QTableView, but when I try this:


bool QTableView::event(QEvent *event)
{
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)
{
etc

The compile error is no 'bool QTableView::event(QEvent*)' member function declared in class 'QTableView'

Any advice on how to do this?

Lykurg
2nd May 2010, 17:36
you have to alter your header file and declare that function! And you also want to name your subclass not like the original file. After all, have you subclassed QTableView? and check if the event is a key event before casting it!

waynew
2nd May 2010, 19:51
Thanks Lykurg. I understand what you mean about declaring in the header and checking for key event.
I have a new QTableView object. But I don't understand how to structure the event so it only applies to the view.

waynew
4th May 2010, 01:48
Solved by using MainWindow::eventFilter