Results 1 to 3 of 3

Thread: How disable up/down arrow press signal in QTableView

  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How disable up/down arrow press signal in QTableView

    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:

    Qt Code:
    1. bool rs_TablaROMS::eventFilter(QObject *objeto, QEvent *evento) {
    2.  
    3. if (evento->type() == QEvent::KeyPress) {
    4. QKeyEvent *kEvento = static_cast<QKeyEvent *>(evento);
    5.  
    6. if (kEvento->key() == Qt::Key_Down || kEvento->key() == Qt::Key_Up) {
    7. // do nothing
    8. }
    9.  
    10. }
    11. if (evento->type() == QEvent::KeyRelease) {
    12. QKeyEvent *kEvento = static_cast<QKeyEvent *>(evento);
    13. if (kEvento->key() == Qt::Key_Return) {
    14. emit doubleClicked(QModelIndex());
    15. }
    16. if (kEvento->key() == Qt::Key_Down || kEvento->key() == Qt::Key_Up) {
    17. qDebug() << "release";
    18.  
    19. }
    20.  
    21. }
    22. return QObject::eventFilter(objeto, evento);
    23. }
    To copy to clipboard, switch view to plain text mode 

    Key press is not ignored and "release" is actually printed on key press. What i'm doing wrong?
    Always trying to learn >.<

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How disable up/down arrow press signal in QTableView

    I will suggest not to filter the key events, instead let the key event be processed normally.

    I will suggest connecting to slot
    Qt Code:
    1. void QAbstractItemView::entered ( const QModelIndex & index ) [signal]
    To copy to clipboard, switch view to plain text mode 
    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();
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How disable up/down arrow press signal in QTableView

    Thanks a lot!! Works perfectly!!
    Always trying to learn >.<

Similar Threads

  1. QML manually emit key press signal
    By mushroom in forum Qt Quick
    Replies: 1
    Last Post: 18th August 2011, 17:02
  2. Disable row/rows in QTableView
    By scott_hollen in forum Qt Programming
    Replies: 6
    Last Post: 28th March 2011, 18:16
  3. Tab behavior versus Arrow in QTableView
    By klahey in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2010, 13:58
  4. disable clicked() signal
    By mattia in forum Newbie
    Replies: 2
    Last Post: 27th February 2008, 10:27
  5. QTableView: disable row header
    By mattie in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2006, 12:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.