Results 1 to 3 of 3

Thread: keyPressEvent not catching regular keys

  1. #1
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default keyPressEvent not catching regular keys

    I am working on a simple text editor and am trying to catch a few keys, like "[" so I can add in "]" automatically. The handler only fire on special keys like shift, ctrl, f*. I slimmed my code down to this to test when it was not working:
    Qt Code:
    1. void Editor::keyPressEvent(QKeyEvent *evt)
    2. {
    3. qDebug() << "Key pressed";
    4. }
    To copy to clipboard, switch view to plain text mode 
    The characters are printed in the plainTextEdit correctly, but I only get qDebug output for special keys, like I mentioned. I have never had this problem before, in Qt or regular console programs, and my searches turn up the opposite problem. Any ideas on where to look would be a great help.

    <edit>
    I am using QSyntaxHighlighter in a separate class, could that be what is interfering?
    </edit>
    Last edited by admkrk; 12th March 2016 at 04:19.

  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: keyPressEvent not catching regular keys

    Have you checked if the normal key strokes are received via the viewportEvent() method?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: keyPressEvent not catching regular keys

    Hi,

    I am not sure how that would work? To be honest I am not really sure how to even implement it correctly, or what to return.

Similar Threads

  1. some keys are not working(keyPressEvent)
    By sanjeet in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 12th January 2018, 22:38
  2. Catching exceptions with Qt
    By The_Fallen in forum Qt Programming
    Replies: 6
    Last Post: 30th July 2010, 20:39
  3. Qt - catching interrupts
    By rishid in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2008, 15:17
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 13:26
  5. Catching X Events
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2006, 13: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.