[Qt-interest] KeyPressEvent hinders eidting the QTextEdit Check the Code snippet
Sujan Dasmahapatra
sdh at lmwindpower.com
Fri Jun 10 09:10:25 CEST 2011
Dear All
Please check the code snippet below
void CTextEditor::keyPressEvent ( QKeyEvent * e )
{
setFocusPolicy(Qt::StrongFocus);
QString text = e->text();
hlighter->pattern = text;
QTextEdit::keyPressEvent(e);
}
void CMyHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setForeground(Qt::darkMagenta);
QRegExp expression(pattern);
while (length >= 0) {
int index = text.indexOf(expression);
length = length + expression.matchedLength();
setFormat(index, length, myClassFormat);
}
}
CTextEditor is QTextEdit and CMyHighLighter is a QSyntaxHighLighter. I
am trying to capture the text from the keyboard input and put some color
on that. But I am unable to achieve this ..Please suggest something
anyhelp would be highly appreciated. Thanks sujan
Kind Regards,
Sujan Dasmahapatra
Project Leader, Aero Group
Aero Group
Tel +91 80 66470248
Mob
sdh at lmwindpower.com <mailto:%25EMAIL%25>
LM Wind Power Blades
lmwindpower.com
Together we capture the wind to power a cleaner world
________________________________
This e-mail and any attachments are confidential. If you are not the
named or intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any purpose,
or store or copy the information in any medium. Any unauthorized
disclosure, use or storage is prohibited and might be unlawful.
From: qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com
[mailto:qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com] On Behalf
Of Sujan Dasmahapatra
Sent: Friday, June 10, 2011 11:12 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] KeyPressEvent hinders eidting the QTextEdit
Dear Eric
How can I ask QSyntaxHighlighter to highlight only a part of the text.
That text I am taking from keyBoardPressEvent.
Kind Regards,
Sujan Dasmahapatra
Project Leader, Aero Group
Aero Group
Tel +91 80 66470248
Mob
sdh at lmwindpower.com <mailto:%25EMAIL%25>
LM Wind Power Blades
lmwindpower.com
Together we capture the wind to power a cleaner world
________________________________
This e-mail and any attachments are confidential. If you are not the
named or intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any purpose,
or store or copy the information in any medium. Any unauthorized
disclosure, use or storage is prohibited and might be unlawful.
From: qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com
[mailto:qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com] On Behalf
Of Eric Clark
Sent: Wednesday, June 08, 2011 11:00 PM
To: Qt Interest (qt-interest at trolltech.com)
Subject: Re: [Qt-interest] KeyPressEvent hinders eidting the QTextEdit
Sujan,
Have you looked into using the QSyntaxHighlighter class to do this?
Highlighting text while the user edits it is exactly what it is designed
to do.
Thanks,
Eric
From: qt-interest-bounces+eclark=ara.com at qt.nokia.com
[mailto:qt-interest-bounces+eclark=ara.com at qt.nokia.com] On Behalf Of
Sujan Dasmahapatra
Sent: Wednesday, June 08, 2011 10:04 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] KeyPressEvent hinders eidting the QTextEdit
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.
Kind Regards,
Sujan Dasmahapatra
Project Leader, Aero Group
Aero Group
Tel +91 80 66470248
Mob
sdh at lmwindpower.com <mailto:%25EMAIL%25>
LM Wind Power Blades
lmwindpower.com
Together we capture the wind to power a cleaner world
________________________________
This e-mail and any attachments are confidential. If you are not the
named or intended recipient, please notify the sender immediately and do
not disclose the contents to any other person, use it for any purpose,
or store or copy the information in any medium. Any unauthorized
disclosure, use or storage is prohibited and might be unlawful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110610/27bee426/attachment.html
More information about the Qt-interest-old
mailing list