how to color certain words in a textedit
hi
i'm using qt3.0.i have to color certain strings/keywords in a textedit while opening the file as well as adding characters in a newly opened file which is similar to qteditor environment.
And also i have to parse the file for the words which should match the predefined words.
for eg.: ScanIn,ScanOut
i have to color the above two words and also check for predefined words,if it is not in the list i have to give an error message.
Please help me,its very urgent.
Give some example coding to do the task.
thanks in advance,
bose.
Re: how to color certain words in a textedit
Set the text format of your text edit to rich text and then add html tags for changing the color of the text around your keywords.
cheers
Re: how to color certain words in a textedit
hi munna
thanks for your reply.could you please give me a sample coding.
thanks
bose.
Re: how to color certain words in a textedit
You should take a look at QSyntaxHighlighter class.
Re: how to color certain words in a textedit
hi wysota sir,
the main objective of my application is to check the keywords,please help me regarding
that part.
thank you.
Re: how to color certain words in a textedit
Quote:
Originally Posted by chandrabose.s
hi wysota sir,
the main objective of my application is to check the keywords,please help me regarding
that part.
thank you.
Did you read QSyntaxHighlighter documentation?
There is even an example of the intended usage.
Inherit your syntax highlighter from QSyntaxHighlighter and implement:
void QSyntaxHighlighter::highlightBlock ( const QString & text ) [pure virtual protected]
Re: how to color certain words in a textedit
hi jpn
actually i'm using Qt3.0.3 and in that version there is no any member named highlightblock() in QSyntaxhighlighter class.Anyway i will try using the highlightparagraph() in Qt3.0.3 version.
Re: how to color certain words in a textedit
hi
can anyone help me how to instantiate the QSyntaxHighlighter() class,and for coloring the words.
please reply, i need someones help.
Re: how to color certain words in a textedit
Sorry for missing the point that you were using Qt3.. ;)
But hmm, it seems that QSyntaxHighlighter wasn't introduced until in Qt 3.1.0?
Re: how to color certain words in a textedit
hi jpn
help me how can i instantiate the QSyntaxhighlighter class.
In Qt3.0.3 how can i color the text,is it possible if so please give me a sample coding.
i'm hanging with this problem please any one help me.
Re: how to color certain words in a textedit
Hi,
In your document search for every instance of your keyword and then around that word add a HTML tag which will give a different color to it.
Example :
QtCenter is the ultimate forum.
If you want a different color for 'ultimate', then search for ' ultimate ' (inculde space so that you get whole words) and replace it with '<font color = 'your color'> ultimate </font>.
Now the line is :
QtCenter is the <font color = 'your color'> ultimate </font> forum.
Set your text edit's format as RICH TEXT.
cheers
Re: how to color certain words in a textedit
Quote:
Originally Posted by chandrabose.s
help me how can i instantiate the QSyntaxhighlighter class
Unfortunately it seems to be impossible. As I mentioned in my previous post, QSyntaxHighlighter wasn't introduced until in a later Qt version, 3.1.0.
Changes 3.1.0
So I guess you will have to simply manually search for the occurences of the keywords, as munna suggested.
Re: how to color certain words in a textedit
hi
fine munna, thats working.i'll try using that to implement my code.