Results 1 to 2 of 2

Thread: Transparent background on QLabel on transparent QWidget

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Transparent background on QLabel on transparent QWidget

    Yes, I know. I read all of the threads which had to do with this, but I couldn't extract any information which could have been helpful to me.

    Here's what I need:
    I am trying to create a custom QWidget which doesn't use the default system frame, but instead its own. The frame is irregularly shaped, and I want to use setMask() to show only the opaque parts of the QWidget "Dialog". Now, everything is fine, the dialog is transparent as it should, but the images aren't. I have png images which use transparency and on the dialog, the system background shows up, which makes it not so transparent after all. I tried using:
    Qt Code:
    1. labelWithImage->setMask(QPixmap("/app/labelImage.png").mask());
    To copy to clipboard, switch view to plain text mode 
    but nothing happened. Then I tried setting the Qt::WA_NoSystemBackground, or Qt::WA_ContentsPropagated, but that resulted in weird results. I know this is possible because I saw some people do it in this thread. Look at the apple image on the first post. Yes it's ugly but how did they implement it? They just didn't include how to do it

    An example:
    As you can see, the background of the label isn't transparent. Now I have an image where the transparent pixels show up as that color. How would I solve this?
    Last edited by codeslicer; 13th February 2008 at 00:46. Reason: updated contents

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Transparent background on QLabel on transparent QWidget

    ... No one even replied here. But I finally solved it using:
    Qt Code:
    1. void resizeEvent(QResizeEvent *e){
    2. QDialog::resizeEvent(e);
    3. //label_2->setAttribute(Qt::WA_ContentsPropagated );
    4. QPixmap pixmap(":/new/prefix1/stand.png");
    5. label_2->setPixmap(pixmap);
    6. label_2->setMask(pixmap.mask());
    7. QRegion reg(frameGeometry());
    8. reg-=QRegion(geometry());
    9. reg+=childrenRegion();
    10. setMask(reg);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Also, I used 2 horizontal spacers to center my object in the widget. Otherwise the Mask would cover the wrong part of the widget. But I have a question. My widget is a rectangle with 4 "fixed" size corners and then "expanding" size spacers, which resize depending on the window. When I resize it it seems to flicker a lot, maybe because it's an irregular shape. (There is this "stand" on the bottom which makes it look like commonly used electronic gadget) So basically it's not exactly a rectangle. And how do I make a size grip on the irregular object? Thanks for all the helpful people like wysota and marcel who helped me with my previous problems.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 19:51
  2. Replies: 1
    Last Post: 5th April 2006, 17:44

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.