Entire form
When you set up the Qt form (Qmainwindow, Qdialog), use the
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.
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.
Draw a translucent rounded rectangle qpainter *painter = new Qpainter (this);p Ainter->setpen (qt::nopen);p Ainter->setbrush (Qcolor ( 0,170,255,100)); The last item is transparency painter->setopacity (0.6);p ainter->drawroundrect (0,0,100,100,10,10);//Draw rounded rectangles
Sets the background color of a control to semitransparent 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)); The last item is 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.
[Learning Record] Transparency settings for QT form controls