PDA

View Full Version : QBrush texture pattern



edb
17th April 2007, 09:17
Hi,

I have a QGraphicsScene and I wish to draw some text on the foreground, a repeated string, but randomly spread over the entire scene (like a watermark). I create a QBrush with a Qpixmap as below....



QBrush brush;
QPixmap pix(200,70);
pix.fill(Qt::transparent);
QPainter paint(&pix);
paint.setPen("black");
paint.setOpacity(0.75);
paint.drawText(10,10,"THISTEXT");
brush.setTexture(pix);


What happens is that if I set this brush as my foregroundbrush for the scene, THISTEXT appears in rows and columns as foreground. I would like this to be less organised. THISTEXT should occur frequently and in a non-ordered way. How can I do this? Is there another way to add a text watermark to the foreground of a QGraphicsScene (QT4)?

Thanx!

Ellen

marcel
17th April 2007, 09:28
Draw the text rotated in the pixmap by some random angle in each drawForeground();
You can do this by altering the painter matrix.

Regards

marcel
17th April 2007, 09:36
Actually no, forget that, it won't work.
You must not use a pattern, just spread the text randomly in drawForeground over the entire viewable rect.

aamer4yu
17th April 2007, 10:11
to set ordered pixmap as background, you can also use QPainter::drawTiledPixmap this will fill the background or the foreground with the igven pixmap....

also if u want random placement, u will have to make some algorithm for the same.
one i can think of is...



textPixmap = some pixmap ;
for whole area of bacground
{
tempPixmap = rotate(textPixmap, x, y , iteration , angle)
painter->drawPixmap(tempPixmap);
}

u can make a rotate function based on the current position of the text, the ith text u are drawing and so on.. This will give the radom effect.

Hope this helps :)

edb
17th April 2007, 13:18
I don't know how to add different pixmaps (with different rotations) to the foreground. Now I use one QBrush which spreads one pixmap in that ordered way.
Another thing I don't see is how rotating the pixmap can solve my column/row order? What I know get is a column with the text, a column without text, a column with text.... ie the QBrush tiles the pixmap until it is filled. Example: Assume below is a QGraphicsScene and the text I want to show randomly across the scene is T, This is what I get (. is an open space, no text on foreground

---------------------------------
| T.....T.....T.....T.....T.....T|
| T.....T.....T.....T.....T.....T|
| T.....T.....T.....T.....T.....T|
| T.....T.....T.....T.....T.....T|
---------------------------------

What I would like to get is the following:
---------------------------------
| T...T....TT....T.... T.... T. |
| T. T.....T.....T................ T|
| .......T..... T...T......T..TT..|
| T..... T.....T....T.....T..T.T|
---------------------------------

Or something like that. I want as few gaps as possible in an unstructured way. I can't really draw interline text here....
I don't know beforehand (when setting the brush) how big the scene will be...

I just want to draw a watermark on top of the scene which is composed of a string... Something like what happens on google maps (http://maps.google.com/). You can hardly see it, but it is there!

Ellen