Results 1 to 6 of 6

Thread: Can't catch key_down and some keys

  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default

    Hi All
    I am using kepress event for catching key_up key_down buttons but my program cant do this but it can catch A,B,C,D,......Z .What is the problem i cant get it?

    Header file
    Qt Code:
    1. #ifndef BAYRAK_H
    2. #define BAYRAK_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_bayrak.h"
    6. #include <QtGui/QMainWindow>
    7. #include <QKeyEvent>
    8. #include <QTimer>
    9.  
    10. class bayrak : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. bayrak(QWidget *parent = 0);
    16. ~bayrak();
    17.  
    18. private:
    19. Ui::bayrakClass ui;
    20. void load();
    21. void ayar();
    22. protected:
    23. void keyPressEvent(QKeyEvent *keyEvent);
    24.  
    25. protected slots:
    26. void sag();
    27. void sol();
    28. private:
    29. QTimer timer;
    30. QString str[8];
    31. buton *flag[4];
    32. int k;
    33. };
    34.  
    35. #endif // BAYRAK_H
    To copy to clipboard, switch view to plain text mode 

    keyPressEvent.

    Qt Code:
    1. void bayrak::keyPressEvent(QKeyEvent *keyEvent)
    2. {
    3. switch(keyEvent->key())
    4. {
    5. case Qt::Key_Up:
    6. timer.singleShot(150,this,SLOT(sol()));
    7. break;
    8. case Qt::Key_Down:
    9. timer.singleShot(150,this,SLOT(sag()));
    10. break;
    11. default:
    12. QMainWindow::keyPressEvent(keyEvent);
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 27th February 2008 at 07:54. Reason: Posts merged

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

    Default Re: Can't catch key_down and some keys

    How do you know it doesn't work? Maybe the problem is with these slots and not the event handler (it looks ok).

  3. #3
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Can't catch key_down and some keys

    If i change the code like that

    Qt Code:
    1. void bayrak::keyPressEvent(QKeyEvent *keyEvent)
    2. {
    3. switch(keyEvent->key())
    4. {
    5. case Qt::Key_A:
    6. timer.singleShot(150,this,SLOT(sol()));
    7. break;
    8. case Qt::Key_S:
    9. timer.singleShot(150,this,SLOT(sag()));
    10. break;
    11. default:
    12. QMainWindow::keyPressEvent(keyEvent);
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    It works, if i change the keys as A and S it works.But key up and down doesnt work.

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

    Default Re: Can't catch key_down and some keys

    In that case probably there is an event filter applied on the main window or the cursor keys are handled in its event() method. You can apply your own event filter and handle the keys there.

  5. #5
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Can't catch key_down and some keys

    How may i do this?

  6. #6
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Can't catch key_down and some keys

    Ok i solve the problem , the problem was about the strong focus policy.It was using arrow keys.I changed it to no focus and , DONE!!!!

    Thanks Wysota

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.