PDA

View Full Version : keyPressEvent not catching regular keys



admkrk
12th March 2016, 03:47
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:

void Editor::keyPressEvent(QKeyEvent *evt)
{
qDebug() << "Key pressed";
}
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>

anda_skoa
12th March 2016, 12:35
Have you checked if the normal key strokes are received via the viewportEvent() method?

Cheers,
_

admkrk
12th March 2016, 17:34
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.