Results 1 to 5 of 5

Thread: Not getting keyPressEvent in my class?

  1. #1
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Exclamation Not getting keyPressEvent in my class?

    When windowdiplayed( show() ), without clicking the window I am not getting keyPressEvent(-)
    void class::keyPressEvent( QKeyEvent *e ){
    ----
    ----
    }
    So is there any way to get the keyPressEvent() without clicking on my Dialog/Window.
    Thanks in advance.

  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: Not getting keyPressEvent in my class?

    A common pattern used for non-modal dialogs, especialy those which are kept around and re-shown later is this

    Qt Code:
    1. dialog->show(); // show it if hidden
    2. dialog->raise(); // move it on top of sibling windows
    3. dialog->activateWindow(); // make it the active sub window
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Not getting keyPressEvent in my class?

    No. still not getting .Without clicking in the dialog, I am not getting key press event in that class. Any other suggestions.Thanks in advance..
    Quote Originally Posted by anda_skoa View Post
    A common pattern used for non-modal dialogs, especialy those which are kept around and re-shown later is this

    Qt Code:
    1. dialog->show(); // show it if hidden
    2. dialog->raise(); // move it on top of sibling windows
    3. dialog->activateWindow(); // make it the active sub window
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Not getting keyPressEvent in my class?

    So is there any way to get the keyPressEvent() without clicking on my Dialog/Window
    Your operating system/window manager will only send key strokes to your application if it currently has focus. Your dialog will only received keystrokes destined for your application if it is the currently focussed window in your application. Clicking on the dialog gives it that focus, as does calling activateWindow().

    Perhaps you need to describe what you are trying to achieve and/or provide a complete, minimal program that demonstrates the problem.

  5. #5
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Not getting keyPressEvent in my class?

    Yes after clicking, my class is getting key press events,But the same could not achieved by writing dialog->activateWindow(). Is there any way to get events without clicking?Thanks a lot for help.

Similar Threads

  1. Replies: 0
    Last Post: 31st August 2012, 15:58
  2. top level keyPressEvent
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2010, 22:42
  3. keypressevent
    By djwk in forum Newbie
    Replies: 9
    Last Post: 5th July 2010, 03:12
  4. Replace keyPressEvent (dot with tab)
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2008, 11:43
  5. keyPressEvent problem
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2008, 14:16

Tags for this Thread

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.