Results 1 to 2 of 2

Thread: Are transparent QPixmaps possible?

  1. #1
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Are transparent QPixmaps possible?

    Hello.
    I would like to display one pixmap over another (using QLabels) so that both pixmaps show. The bottom pixmap is a bmp image from a file, the top one is a circle.
    When I display the circle over the bmp image (using the code below), the background of the circle is going to cover part of the bmp. I don't want that. I want the circle pixmap to be transparent so that I only get the circle on top on the pixmap and none of the circle's background. Would someone be able to suggest how to modify the below code to make that happen.
    I know you are going to say that I should first display my bmp file as a pixmap and then draw the circle on the same pixmap, but I wonder if this can be done with two pre-existing pixmaps.

    Qt Code:
    1. mainLayout = new QVBoxLayout;
    2. pixmapLabel = new QLabel;
    3. drawLabel = new QLabel(pixmapLabel);;
    4.  
    5. QPixmap pm(600,450);
    6. pm.load("image.bmp");
    7. pixmapLabel->setPixmap(pm);
    8.  
    9. QPixmap pm4(100,100);
    10. QPainter p4(&pm4);
    11. QPen pen4(Qt::white, 3);
    12. p4.setPen(pen4);
    13. p4.drawEllipse(10, 10, 50, 50);
    14. drawLabel->setPixmap(pm4);
    15.  
    16. mainLayout->addWidget(pixmapLabel);
    17. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 

  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: Are transparent QPixmaps possible?

    Qt Code:
    1. mainLayout = new QVBoxLayout;
    2. pixmapLabel = new QLabel;
    3. drawLabel = new QLabel(pixmapLabel);;
    4. QPixmap pm(600,450);
    5. pm.load("image.bmp");
    6. pixmapLabel->setPixmap(pm);
    7.  
    8. QPixmap pm4(100,100);
    9. pm4.fill(Qt::Transparent); // add this!
    10. QPainter p4(&pm4);
    11. QPen pen4(Qt::white, 3);
    12. p4.setPen(pen4);
    13. p4.drawEllipse(10, 10, 50, 50);
    14. drawLabel->setPixmap(pm4);
    15. mainLayout->addWidget(pixmapLabel);
    16. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 

  3. The following 3 users say thank you to marcel for this useful post:

    EarthHobbit (17th February 2017), emobemo (3rd September 2014), eric (19th November 2007)

Similar Threads

  1. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 10:32
  2. Replies: 0
    Last Post: 21st May 2007, 22:38
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Transparent widgets
    By incapacitant in forum Newbie
    Replies: 10
    Last Post: 21st March 2006, 18:01

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.