Entire form
When you set up the Qt form (Qmainwindow, Qdialog), use the
[CPP]View PlainCopy
- Targetform->setwindowopacity ()
function to make it transparent to all controls in the form and in the window.
Ii. Customizing a page or control
When setting a Qwidget (General custom page or control with Qwidget), setting its form transparency directly does not achieve transparency, the method currently found is to use the entire qwidget as a graphical element to set the transparency effect on the graphic element.
[CPP]View PlainCopy
- Qgraphicsopacityeffect *opacityeffect=New Qgraphicsopacityeffect;
- Targetelement->setgraphicseffect (Opacityeffect);
- Opacityeffect->setopacity (0.7);
This can be done with transparency.
Third, set the transparency value in the color
If you need to paint your own shape, control background, borders, text, etc. can be color-colored places to be transparent, only need to set the color of the site a transparency.
[CPP]View PlainCopy
- Draw a translucent rounded rectangle
- Qpainter *painter = new Qpainter (this);
- Painter->setpen (Qt::nopen);
- Painter->setbrush (Qcolor (0,170,255,100)); //Last item for transparency
- Painter->setopacity (0.6);
- Painter->drawroundrect (0,0,100,100,10,10); //Draw rounded rectangles
[CPP]View PlainCopy
- Sets the background color of a control to translucent
- Qwidget *widget = new Qwidget; Qwidget can be any qwidget-derived control
- Widget->setautofillbackground (true);
- Qpalette Palette;
- Palette.setcolor (Qpalette::background, Qcolor (192,253,123,100)); //Last item for transparency
- Palette.setbrush (Qpalette::background, Qbrush (Qpixmap (":/background.png"));
- Widget>setpalette (palette);
- If the background image needs to be transparent, make a background with a translucent PNG image or use the method two to semitransparent the entire control.
This usage is typically used for a few more places where transparency is required, and if the self-painted content is more complex, it is easier to set the overall transparency effect directly.
http://blog.csdn.net/jelly_chen_zo/article/details/45538755
Transparency settings for QT form controls (three methods)