PDA

View Full Version : keyReleaseEvent problem



RENOLD
10th February 2012, 08:38
I am working on this code:

void widget::keyPressEvent (QKeyEvent *e)
{
if(e->key()==Qt::Key_N)
{
function1();
}
}

void widget::keyReleaseEvent (QKeyEvent *r)
{
if(r->key()==Qt::Key_N)
{
function2();
}
}
.
.
.

It means when i press N key my function1() has to call, and when I release N key my function2() has to call. I want to make such that kind of application in which I have to continuously press N key and function 1 will continuously call, and when I release this N key only one time my function2() will call.
Now I am continuously pressing the N key.
But the problem is that my function2() is also continuously called still I haven't release the N key.

Please give your suggestion which will be helpful to me.

:)

RENOLD
13th February 2012, 08:05
Hey friends I done my work using below code, If you will suffer with this problem in future this code become helpful to you,

void widget::keyPressEvent (QKeyEvent *e)
{
if(e->key()==Qt::Key_N)
{
function1();
}
}

void widget::keyReleaseEvent (QKeyEvent *r)
{
if(r->isAutorepeat())
{
r->ignore();
}
if(r->key()==Qt::Key_N)
{
function2();
}
}

Spitfire
15th February 2012, 14:14
In future please use [CODE] tags around code you paste in.