[Qt-interest] How to add an image as the background in an text editor

Roopesh Chander roop at forwardbias.in
Tue Feb 24 18:55:08 CET 2009


On Tuesday 24 February 2009 07:47 PM, Keshava Krishna wrote:
> Hi,
> 
> I am building a text editor where i want to add an image in the 
> background of text ,
> then control the opacity of the text such that the image is partially 
> visible through the text.
> I am currently using QTextEdit class, but i did not find any useful 
> method to add an image at the background.
> can anyone suggest me a way to do this??

The simplest way to get a background image is by setting a stylesheet on 
the QTextEdit widget (setStyleSheet() or set property in Qt-Designer).

But with stylesheets, afaik, getting the image to be seen through the 
text is close to imposs. So, to do that, you can try reimplementing the 
paint method of QTextEdit (and unset the stylesheets you did in the last 
para :D). One implementation I can think of is to subclass QTextEdit, 
and in your MyTextEdit::paint method, draw the image first, then set the 
desired opacity on the painter, and then call QTextEdit::paint().

roop.



More information about the Qt-interest-old mailing list