PDA

View Full Version : How disable up/down arrow press signal in QTableView



aguayro
21st January 2013, 14:47
Hi, need help to know how do a delay row check in a QTableView. When the row changes, the application does some actions, like playing a video. If i select rows keeping key up/down pressed, the application crashes, so i need implement some delay or something to detect if the user has stopped in a row, then start the video.
I was thinking about use EventFilter to ignore key up/down press, and catch only whe them are released.

I've tryed with thi code without luck, key press is not ignored:



bool rs_TablaROMS::eventFilter(QObject *objeto, QEvent *evento) {

if (evento->type() == QEvent::KeyPress) {
QKeyEvent *kEvento = static_cast<QKeyEvent *>(evento);

if (kEvento->key() == Qt::Key_Down || kEvento->key() == Qt::Key_Up) {
// do nothing
}

}
if (evento->type() == QEvent::KeyRelease) {
QKeyEvent *kEvento = static_cast<QKeyEvent *>(evento);
if (kEvento->key() == Qt::Key_Return) {
emit doubleClicked(QModelIndex());
}
if (kEvento->key() == Qt::Key_Down || kEvento->key() == Qt::Key_Up) {
qDebug() << "release";

}

}
return QObject::eventFilter(objeto, evento);
}



Key press is not ignored and "release" is actually printed on key press. What i'm doing wrong?

Santosh Reddy
21st January 2013, 15:05
I will suggest not to filter the key events, instead let the key event be processed normally.

I will suggest connecting to slot
void QAbstractItemView::entered ( const QModelIndex & index ) [signal] In the that slot start a timer of (say 3 seconds), store the timerId, and row number. Whenn the timer expires and and executes the timerEvent(), check for timerId() and then start the video. In a case where row has changed with in 3 seconds timerId will have been changed, will always contain the latest timerId, and row. Hence all the earlier timers are ignored in timerEvent();

aguayro
21st January 2013, 16:02
Thanks a lot!! Works perfectly!!