Results 1 to 4 of 4

Thread: Forward key event to other widget?

  1. #1
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Forward key event to other widget?

    Hello,

    I have a QTableWidget based class with an reimplemented keyPressEvent(...) method.

    Unfortunately the window that holds the tableWidget does not react on the Tab-key any more (catchword: tab order). the tab order works as long as the tableWidget is not reached. As soon as the tabWidget has the focus the Tab-key only switches from one table cell to the next.
    The tab order of the parent widget is "stopped" in from this moment on.

    How can I make the tabWidget ignore the Tab-key and leave it to the surrounding widget that hold the tabWidget?

    My implementation of the keyPressEvent(). No magic so far:
    Qt Code:
    1. void MyTableWidget::keyPressEvent( QKeyEvent* event )
    2. {
    3. switch( event->key() )
    4. {
    5. case Qt::Key_Home:
    6. setCurrentCell(0, 0);
    7. break;
    8. default:
    9. QTableWidget::keyPressEvent(event);
    10. break;
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Forward key event to other widget?

    Reimplement QObject::event() for your table widget (or its viewport(), try both) and handle Qt::Key_Tab there. Alternatively reimplement QAbstractItemView::focusNextPrevChild() and call implementation of the method from QWidget there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Boron (6th February 2012)

  4. #3
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Forward key event to other widget?

    Thank you.
    The second idea was pretty easy.

    For those having the same "problem" as I had: Here is what I have done:
    Qt Code:
    1. bool MyTableWidget::focusNextPrevChild( bool next )
    2. {
    3. QWidget::focusNextPrevChild(next);
    4. return false; // a "true" also works
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Forward key event to other widget?

    How about just:
    Qt Code:
    1. bool MyTableWidget::focusNextPrevChild( bool next )
    2. {
    3. return QWidget::focusNextPrevChild(next);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 2nd August 2011, 21:15
  2. tree widget item's widget don't respond to any event.
    By quantity in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2011, 04:30
  3. widget load event?
    By scarleton in forum Newbie
    Replies: 2
    Last Post: 16th August 2010, 18:47
  4. Replies: 7
    Last Post: 14th January 2010, 08:47
  5. Widget enter event
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 20th April 2008, 22:40

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.