Results 1 to 7 of 7

Thread: how to overide key press event

  1. #1
    Join Date
    May 2013
    Posts
    20
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Question how to overide key press event

    need to override the keyPressEvent() and make my application to run on customized keys pressed

    tried switch::cases and if conditions on Qt::keys but application is flowing through its own Qt::keyPressEvent();

    also the connect(button1,SIGNAL(pressed()),this,SLOT(readFi le()));....
    pressed() only takes space key from key board but not enter key

    Please Help

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    92
    Thanked 16 Times in 16 Posts

    Default Re: how to overide key press event

    need to override the keyPressEvent()
    Qt Code:
    1. // In .h file
    2. protected:
    3. void keyPressEvent(QKeyEvent* keyEvent)
    4. {
    5. // write your code here
    6. }
    To copy to clipboard, switch view to plain text mode 

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

    maverick (30th May 2013)

  4. #3
    Join Date
    May 2013
    Posts
    20
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default Re: how to overide key press event

    i have already tried that but it is not being called.....

  5. #4
    Join Date
    Aug 2012
    Location
    Loughborough, UK
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: how to overide key press event

    it only gets called for non special characters. Doesnt get called by tab key for instance.

    If you create an event filter and grab keyboard in that component it works, but that's not always desired behaviour either?

  6. #5
    Join Date
    Aug 2012
    Location
    Loughborough, UK
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: how to overide key press event

    i overcame the grab keyboard problem by grabbing it on show and releasing it on hide. ( This was needed because the tab keypresses in question were aimed at a class which inherited from QDialog it would seem....?)

  7. #6
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 9 Times in 9 Posts

    Default Re: how to overide key press event

    use event filter ... on that object

  8. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    10
    Thanked 13 Times in 12 Posts

    Default Re: how to overide key press event

    Try to use event filters, Key combinations . QKeyEvent and use Qt::AltModifier or event->key()==Qt::Key_L// Key_alphabets.

Similar Threads

  1. long mouse press event
    By tonylin0826 in forum Newbie
    Replies: 5
    Last Post: 27th September 2012, 17:24
  2. Long press event
    By alfah in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2011, 14:26
  3. Key Press Event Handling
    By kosasker in forum Newbie
    Replies: 8
    Last Post: 22nd March 2011, 16:49
  4. Paint event function in key press event
    By soumya in forum Qt Programming
    Replies: 6
    Last Post: 2nd February 2010, 13:40
  5. Key Press Event trouble
    By morraine in forum Newbie
    Replies: 6
    Last Post: 18th August 2008, 09:43

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
  •  
Qt is a trademark of The Qt Company.