Results 1 to 3 of 3

Thread: keyReleaseEvent problem

  1. #1
    Join Date
    Feb 2012
    Posts
    27
    Thanked 2 Times in 2 Posts

    Default keyReleaseEvent problem

    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.


  2. #2
    Join Date
    Feb 2012
    Posts
    27
    Thanked 2 Times in 2 Posts

    Default Re: keyReleaseEvent problem

    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();
    }
    }

  3. The following user says thank you to RENOLD for this useful post:

    0backbone0 (27th August 2015)

  4. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: keyReleaseEvent problem

    In future please use [CODE] tags around code you paste in.

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.