PDA

View Full Version : Can't catch key_down and some keys



anafor2004
27th February 2008, 04:24
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

#ifndef BAYRAK_H
#define BAYRAK_H

#include <QtGui/QMainWindow>
#include "ui_bayrak.h"
#include <QtGui/QMainWindow>
#include <QKeyEvent>
#include <QTimer>

class bayrak : public QMainWindow
{
Q_OBJECT

public:
bayrak(QWidget *parent = 0);
~bayrak();

private:
Ui::bayrakClass ui;
void load();
void ayar();
protected:
void keyPressEvent(QKeyEvent *keyEvent);

protected slots:
void sag();
void sol();
private:
QTimer timer;
QString str[8];
buton *flag[4];
int k;
};

#endif // BAYRAK_H

keyPressEvent.


void bayrak::keyPressEvent(QKeyEvent *keyEvent)
{
switch(keyEvent->key())
{
case Qt::Key_Up:
timer.singleShot(150,this,SLOT(sol()));
break;
case Qt::Key_Down:
timer.singleShot(150,this,SLOT(sag()));
break;
default:
QMainWindow::keyPressEvent(keyEvent);

}

wysota
27th February 2008, 08:55
How do you know it doesn't work? Maybe the problem is with these slots and not the event handler (it looks ok).

anafor2004
27th February 2008, 09:25
If i change the code like that


void bayrak::keyPressEvent(QKeyEvent *keyEvent)
{
switch(keyEvent->key())
{
case Qt::Key_A:
timer.singleShot(150,this,SLOT(sol()));
break;
case Qt::Key_S:
timer.singleShot(150,this,SLOT(sag()));
break;
default:
QMainWindow::keyPressEvent(keyEvent);

}

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

wysota
27th February 2008, 09:50
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.

anafor2004
27th February 2008, 09:57
How may i do this?

anafor2004
27th February 2008, 10:00
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