Results 1 to 2 of 2

Thread: QEvent::KeyPress for Enter and Return, Detection Qt::Modifiers on Enter doesn't work

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QEvent::KeyPress for Enter and Return, Detection Qt::Modifiers on Enter doesn't work

    Hello,

    i have a eventFilter where i catch a presses Key like this:

    Qt Code:
    1. if ( event->type() == QEvent::KeyPress)
    2. {
    3. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    4.  
    5. switch ( keyEvent->key() )
    6. {
    7. case Qt::Key_Enter:
    8. qDebug() << "Enter";
    9. case Qt::Key_Return:
    10. {
    11. qDebug() << "Return";
    12. if( keyEvent->modifiers()==Qt::NoModifier )
    13. {
    14. qDebug() << "NoModifier";
    15. }
    16. if( keyEvent->modifiers()==Qt::ShiftModifier )
    17. {
    18. qDebug() << "ShiftModifier";
    19. }
    20. break;
    21. }
    22. case Qt::Key_Escape:
    23. qDebug() << "Escape"
    24. default:
    25. break;
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    when I press "Return", everything is OK i get as output

    Return
    NoModifier or ShiftModifier

    but when I press "Enter" the detection of the modifiers doesn't work. The output is always

    Enter
    Return
    (no output of "NoModifier" or "ShiftModifier")

    What I'm doing wrong?

    Thx
    Stefan

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QEvent::KeyPress for Enter and Return, Detection Qt::Modifiers on Enter doesn't w

    Have you tried changing the check for the shift modifier to that it checks if the shift modifier is present?
    Currently you check if it is the only modifier.

    In general: you have if statements that that do not handle all cases. If they do not trigger, their conditions are not met.
    You can easily find out why by looking at the values using in these conditions. That's called debugging.

    Cheers,
    _

Similar Threads

  1. QSpinBox doesn't consume the enter key
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 18th May 2011, 19:30
  2. keypressEventFilter() to accept Enter and Return Tab
    By ad5xj in forum Qt Programming
    Replies: 8
    Last Post: 31st July 2007, 17:18
  3. Replies: 2
    Last Post: 17th July 2006, 14:52
  4. QEvent::Enter
    By incapacitant in forum Newbie
    Replies: 6
    Last Post: 22nd March 2006, 08:07
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 19:43

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.