Results 1 to 5 of 5

Thread: QBrush texture pattern

  1. #1
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default QBrush texture pattern

    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....

    Qt Code:
    1. QBrush brush;
    2. QPixmap pix(200,70);
    3. pix.fill(Qt::transparent);
    4. QPainter paint(&pix);
    5. paint.setPen("black");
    6. paint.setOpacity(0.75);
    7. paint.drawText(10,10,"THISTEXT");
    8. brush.setTexture(pix);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBrush texture pattern

    Draw the text rotated in the pixmap by some random angle in each drawForeground();
    You can do this by altering the painter matrix.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBrush texture pattern

    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.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBrush texture pattern

    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

  5. #5
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QBrush texture pattern

    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

Similar Threads

  1. QBrush pattern problem
    By ilovethisgame in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2012, 22:07
  2. Textures + Multiple QGLWidgets
    By KShots in forum Qt Programming
    Replies: 8
    Last Post: 19th October 2007, 21:23
  3. QGLWidget : unable to texture a quad
    By yellowmat in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2006, 16:47
  4. Qt, Databases & the DAO Pattern
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2006, 16:13

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.