Results 1 to 3 of 3

Thread: QGraphicsTextItem+trasparent fill+png

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsTextItem+trasparent fill+png

    Hello,
    I want to render text item to image file (i.e. png), but keeping background transparent.
    Qt Code:
    1. QGraphicsScene graphics_scene;
    2.  
    3. QGraphicsTextItem* text_item;
    4.  
    5. // some code to add item and set text
    6.  
    7. text_item->setPos(0, 0);
    8.  
    9. QRectF source_text_item_rect = text_item->sceneBoundingRect();
    10.  
    11. QRectF target_text_item_rect;
    12.  
    13. target_text_item_rect.setX(0);
    14. target_text_item_rect.setY(0);
    15. target_text_item_rect.setSize(source_text_item_rect.size());
    16.  
    17. QPixmap pixmap_with_text(qRound(target_text_item_rect.width()), qRound(target_text_item_rect.height()));
    18.  
    19. pixmap_with_text.fill(Qt::Transparent);
    20.  
    21. QPainter pixmap_painter(&pixmap_with_text);
    22.  
    23. graphics_scene.render(&pixmap_painter, target_text_item_rect, source_text_item_rect);
    24.  
    25. QString image_with_text_filename; //some filename
    26.  
    27. return pixmap_with_text.save(image_with_text_filename, "PNG", 100);
    To copy to clipboard, switch view to plain text mode 

    This produce pixmap with only transparent color and no text.

    If set fill color to any (non-transparent), then it is filled with that color and with text which is over.

    Is it possible to make transparent filling?
    Last edited by wysota; 25th November 2008 at 08:10.

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.