Results 1 to 7 of 7

Thread: Transparent Pixmap

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Transparent Pixmap

    Hi,

    I am currently working a bit with the QPixmap class. I am looking for a solution how to create a transparent pixmap. I need to create a QGraphicsPixmapItem and add it to the scene.
    I am drawing different symbols( created from rects,polygons,lines <- describing shapes). For example, I would like to add 5 circles to the pixmap and only show those circles on the scene, as they were simple Items, not pixmaps.(in some cases these symbols will be much more complicated)
    Transparency of a pixmap is the issue. By transparency I mean -> transparent background of the pixmap(no background). If I would not add anything to the pixmap and then painted it, nothing would be shown,etc.

    Thank you for any help.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  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: Transparent Pixmap

    Try:
    Qt Code:
    1. pixmap.fill(Qt::Transparent);
    To copy to clipboard, switch view to plain text mode 
    but right after you open a painter on the pixmap, not before.

  3. The following user says thank you to marcel for this useful post:

    maverick_pol (19th December 2007)

  4. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transparent Pixmap

    Thanks.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transparent Pixmap

    Ok,

    Is this code, what you mean?

    Qt Code:
    1. QPixmap world(100,100);
    2. QPainter painter(&world);
    3. world.fill(Qt::transparent);
    4. painter.setPen(Qt::black);
    5. painter.setBrush(QBrush(Qt::black));
    6. painter.drawRect(QRectF(QPointF(0,0),QPointF(50,50)));
    7. iworld.save("C:/world.png","PNG");
    To copy to clipboard, switch view to plain text mode 

    while adding the "world.fill(Qt::transparent)" the whole pixmap is transparent(in the meaning of being empty)

    What am I doing wrong or is there a flow in your answer?
    I can set Brush as Qt::transparent and it fills the rect with no colors(that's ok), but what about the other part of the pixmap? I am currently looking for the answer.

    Thanks for any further help.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #5
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent Pixmap

    Quote Originally Posted by maverick_pol View Post
    Ok,
    while adding the "world.fill(Qt::transparent)" the whole pixmap is transparent(in the meaning of being empty)

    What am I doing wrong or is there a flow in your answer?
    I can set Brush as Qt::transparent and it fills the rect with no colors(that's ok), but what about the other part of the pixmap? I am currently looking for the answer.

    Thanks for any further help.

    Kacper
    What do you mean by the whole pixmap is transparent, you don't see the rect you're drawing afterward ?

  7. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transparent Pixmap

    I can't see anything. The whole pixmap is transparent, as if nothing been drawn.
    world.png file and world2.png (the pixmap is filled with red):
    Attached Images Attached Images
    Last edited by maverick_pol; 19th December 2007 at 16:19.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transparent Pixmap

    Ok, I suppose I have the solution:

    Qt Code:
    1. ....
    2. QPixmap world(100,100);
    3. world.fill(Qt::transparent);
    4. QPainter painter(&world);
    5. ...
    To copy to clipboard, switch view to plain text mode 

    ..right after you open a painter on the pixmap, not before.
    That was a bit misleading.

    Thank you all for help.

    Kacper
    Attached Images Attached Images
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 21:15
  2. Are transparent QPixmaps possible?
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2007, 20:43
  3. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 10:32
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 21:15

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.