Results 1 to 3 of 3

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

  1. #1
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default In QTextEdit - How to change BG color for particular word(Qt 3.3.4)

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: In QTextEdit - How to change BG color for particular word(Qt 3.3.4)

    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]<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>[/html]

    Produces this:
    Attached Images Attached Images
    Last edited by jacek; 9th March 2007 at 22:50. Reason: changed [code] to [html] and wrapped too long lines

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: In QTextEdit - How to change BG color for particular word(Qt 3.3.4)

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.