PDA

View Full Version : In QTextEdit - How to change BG color for particular word(Qt 3.3.4)



joy
9th March 2007, 18:51
Hi everybody,

In QTextEdit field, I need to change the BG color for particular word or marked portion in the line.

In QTextEdit we can change overall BG color for particular Paragraph.

Using QStyleSheet , there is no facility to change font background color.

Help me in this regard

Thanks

vfernandez
9th March 2007, 21:25
Edit: wooops! I didn't read it was for Qt 3.3.4. :(

Can't you just use <span style=" color:#ffffff; background-color:#ff0000;"> ? For instance, this code:

<html><head><meta name="qrichtext" content="1" />
<style type="text/css">p, li { white-space: pre-wrap; }</style></head>
<body style=" font-family:'Bitstream Vera Sans'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
this is some <span style=" color:#ffffff; background-color:#ff0000;">red text</span>.</p>
</body></html>

Produces this:

wysota
9th March 2007, 23:19
I've been browsing Qt3 Designer sources trying to find something that could help, but Designer uses a completely different code and despite that I know it is possible to achieve what you want (Designer editor highlights matching brackets when cursor is on one of the brackets), it looks like it's not possible without much much work. I was unable to find anything that could help and I fear that even if I did, you wouldn't be able to use it in any easy way anyway. So either you need to:
1. think of something different,
2. do the colouring yourself by overriding some paint event, calculating the position of characters you want to colour and paint appropriate areas before the text is rendered,
3. switch to Qt4 :)