I need help with setting the colour of a string to be green in the beginning and red at the end.
The problem right now is that spaces that occur between the two colours disapear.
The code looks like this:
Printable View
I need help with setting the colour of a string to be green in the beginning and red at the end.
The problem right now is that spaces that occur between the two colours disapear.
The code looks like this:
QString isn't responsible for the way it is displayed. Is is just a convinient container for the characters with a bunch of useful features. The way QString is shown depends on the widget which displays it. In your case it is QTextEdit.Quote:
The QString class provides a Unicode character string
Code:
//The string you want to decorate //The widget, which will display string QTextEdit te; //Format first 4 characters //Format the rest of the characters //Make resulting HTML appear on the QTextEdit te.setHtml(redPart + greenPart);
Thanks for this answer Cesar, Will your code respect spaces in the text if they occur between the green and the red part?
Try this code... And ask your questions, if any :)Quote:
Originally Posted by Morea
It works for me if:Quote:
Originally Posted by Cesar
"what ever I enter in the second box, which matches character for character what is in the first box, from right to left, is turned green in the display form"
was what you intended.
But why doesn't the HTML code work with spaces?
Because HTML trimms multiple whitespaces into one. If you want to keep them, transform each of the multiple spaces to " " (keep single ones as they are).
Thanks for all the help so far, but now I'm stuck. I get a crash when the program starts.
The problem seems to be with the creation of the red/green part.
The point of the program is to press enter, get a random text, and directly start writing the same thing (marked red/green if wrong/right).
I attach a tgz with the code.
It's produced with dev-c++ in windows.
Ah, is it perhaps the infinite loop I get with all the textChanged signals that are emitted, and the KollaText() slot that receives it and then again emits a textChanged signal..
It might be! But I doesn't seem possible to change to a keypressed event or something like that. Any ideas, or should I just use the code that cesar sent earlier?
Now it works fine! I strongly recomend anyone using Dev-C++ to rebuild everything once in a while, otherwise you might have parts that is not properly updated.