Results 1 to 3 of 3

Thread: pressing and holding a keyEvent

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default pressing and holding a keyEvent

    Hi
    How an event can be created by pressing and holding a key like "Ctrl" button on keyboard? For example:
    Qt Code:
    1. keyPressingHoldingEvent(QKeyEvent * event)// is there any event function for pressing and holding a key?
    2. {
    3. if(event->key() == Qt::Key_Control)//if "Ctrl" is pressing and holding
    4. //do something
    5. else
    6. //do some other thing (if "Ctrl" is not holding)
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: pressing and holding a keyEvent

    You detect the press, then start a timer. if the release happens before the timer is through, it is a key press/release, if the timer fires, it is a press and hold.

    Cheers,
    _

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

    Alex22 (5th March 2016)

  4. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: pressing and holding a keyEvent

    Qt Code:
    1. void keyPressEvent(QKeyEvent *keyP)
    2. {
    3. if(keyP->key()==Qt::Key_Control)
    4. setCursor(Qt::ClosedHandCursor);
    5. }
    6.  
    7. void keyReleaseEvent(QKeyEvent *keyR)
    8. {
    9. if(keyR->key()==Qt::Key_Control)
    10. setCursor(Qt::CrossCursor);
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Holding Program until QWidget is closeed
    By FreddyKay in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2013, 14:37
  2. Replies: 6
    Last Post: 22nd September 2008, 11:53
  3. figuring out who's holding up
    By baray98 in forum General Programming
    Replies: 4
    Last Post: 7th December 2007, 18:29
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42
  5. what item QCanvasItemList is holding..
    By Kapil in forum Newbie
    Replies: 17
    Last Post: 25th April 2006, 14:57

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.