Results 1 to 7 of 7

Thread: QDialog keypress event

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QDialog keypress event

    I am trying to capture the keypress event in a QDialog.

    In my constructor, I have this as the last line:
    QObject::installEventFilter(this);


    Then I have this method:
    Qt Code:
    1. bool frmFileDialog::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. QKeyEvent *keyEvent;
    4.  
    5. if(event->type() == QEvent::KeyPress){
    6. keyEvent = static_cast<QKeyEvent *>(event);
    7. }
    8. else{
    9. return QObject::eventFilter(obj, event);
    10. }
    11. if(keyEvent->isAutoRepeat()){
    12. return QObject::eventFilter(obj, event);
    13. }
    14.  
    15. if(keyEvent->key() == Qt::Key_1){
    16. keyEvent->accept();
    17. this->close();
    18. return true;
    19. }
    20. else{
    21. return QObject::eventFilter(obj, event);
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    The issue I am having is if any of regular keys are typed on the keyboard (i.e. the 1 key), the method is not entered at all. If "F1" or the tab key are pressed, it is entered. What do I need to capture any key that is pressed in this Dialog?

    Thanks,
    Kevin
    Last edited by anda_skoa; 2nd February 2015 at 09:22. Reason: missing [code] tags

Similar Threads

  1. Handling keypress event in textedit
    By Niamita in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2011, 10:07
  2. QEvent::KeyPress problem, when will this event appear?
    By batileon in forum Qt Programming
    Replies: 11
    Last Post: 17th June 2011, 05:23
  3. problem with keypress event and QTableView
    By ranna in forum Qt Programming
    Replies: 4
    Last Post: 24th August 2009, 16:13
  4. how to combine keypress event and mousebuttonpress event?
    By hildebrand in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2009, 23:08
  5. keypress event
    By vishesh in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2007, 14:12

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.