PDA

View Full Version : KeyPressEvent hinders eidting the QTextEdit



sujan.dasmahapatra
8th June 2011, 16:01
Dear Friend
I have a QTextEdit I want to capture the KeyPressEvent and take each of the text user enters through keyboard. Late I want to change the color of those text. But when I reimplement KeyPressEvent() my text edit becomes choked means I am not able to edit anything. Why this is happening I want to be able to write text in the editor. Any suggestion would be highly appreciated. Thanks sujan

Check the code snippet

void CTextEditor::keyPressEvent ( QKeyEvent * e )
{
setFocusPolicy(Qt::NoFocus);
QString text = e->text();
tree->hlighter->highlightBlock(text);
}

void CTextEditor::keyPressEvent ( QKeyEvent * e )
{
setFocusPolicy(Qt::NoFocus);
QString text = e->text();
tree->hlighter->highlightBlock(text);
}

Just because I reimplemented KeyPressEvent I am not able to enter anything in the editor. Please give some suggestions.

mvuori
8th June 2011, 17:01
The first thing that comes to mind is setFocusPolicy(Qt::NoFocus), where you tell Qt that the control has no focus, so -- no editing. Otherwise, I'm not familiar with what keyPresseEvent should do.