Results 1 to 2 of 2

Thread: issues regarding how to reimplement keyPressEvent()

  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default issues regarding how to reimplement keyPressEvent()

    Dear Friends,
    I need to override the Esc key event so i tried to reimplement keyPressEvent() of QDialog. but it is not executed when i pressed any key. the code is given below.
    Qt Code:
    1. void Myclass::keyPressEvent(QKeyEvent *e)
    2. {
    3. if(e->key()==Qt::Key_Escape)
    4. {
    5. QMessageBox(0,"Error","Key press");
    6. }
    7. else
    8. {
    9. QDialog::keyPressEvent(e);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 


    while defining QDialog i gave setFocusPolicy(Qt::StrongFocus) as like below
    Qt Code:
    1. win = new QDialog(this);
    2. QDialog::setFocusPolicy(Qt::StrongFocus);
    To copy to clipboard, switch view to plain text mode 

    can any body help me where im getting wrong

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: issues regarding how to reimplement keyPressEvent()

    the key event is being received by another widget in your dialog which has input focus.
    You should install an evenFilter for that widget in your dialog and there trap the QKeyEvent.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QGraphicsItem keyPressEvent oddness
    By jonks in forum Qt Programming
    Replies: 5
    Last Post: 3rd June 2009, 15:08
  2. keyPressEvent issue
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2008, 15:39
  3. Replies: 6
    Last Post: 13th May 2008, 13:19
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 12:26
  5. Replies: 3
    Last Post: 27th November 2006, 09:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.