This works:
Qt Code:
myWidget->setAutoFillBackground(false); myWidget->setMask(pixmap.createHeuristicMask();To copy to clipboard, switch view to plain text mode
Easy, functional, and doesn't require custom widgets. You just need to remember to update the mask whenever the widget's layout changes.
functioning.png
Note: Since createHeurisiticMask() uses whatever colors are in each of the corners and chips away from there, if your widget has legitimate pixels in one of the corners they will be eaten.
If such is the case, you might prefer createMaskFromColor() instead, using the color of the transparent pixel Qt uses. For me, this oddly appears to be QColor(173, 240, 13).
I tried to find a constant defined somewhere with that value, but I can't locate one. Qt::transparent, and Qt::color0 / Qt::color1 don't match it.
If QColor(173,240,13) doesn't work for you, you can instead save the pixmap (pixmap->save()) and see what color is used in your version of Qt. Obviously this method isn't future-proof however.
[Edit:] ROFL. QColor, being lime green, I thought they were just using the color from the Qt logo (which is actually quite a bit darker). Turns out in hexadecimal it's 0xADF00D, so in ARGB (but the alpha gets lost) it's probably 0xBAADF00D, or maybe 0xDEADF00D, common debug/error values.
Someone should submit a patch for this, and make it use Qt::transparent as the color, or create a new color for it (Qt::invisible), so it can be assured to not break in future builds.
Or, preferablly, just return a 32 bit pixmap with proper alpha. Then you can just do: pixmap->mask().
Bookmarks