1. Set the background color of the form.
Add in the constructorCode, You need to add the header file qpalette or qgui
Qpalette pal = palette ();
Pal. setcolor (qpalette: Background, qcolor (0x00, 0xff, 0x00,0x00 ));
Setpalette (PAL );
You can set the background color of the form to completely transparent.
Effect:
The window is transparent, but the window control is not transparent. The qlabel control only displays words and the control background color is transparent;
The form client area is completely transparent.
2. Use the setattribute function (QT: wa_translucentbackground, true );
In the same constructor, the effect is the same as that in the first method.
3. The window and Its above controls are translucent:
Setwindowopacity (0.7)
This function can adjust the transparency by 10 levels. With the qslider control, it can be used as a control bar.
Effect: the window and controls are translucent.
4. The overall window is not transparent and partial transparency:
Use the Clear mode drawing in the paint event.
Void testwindow: paintevent (qpaintevent *)
{
Qpainter P (this );
P. setcompositionmode (qpainter: compositionmode_clear );
P. fillrect (10, 10,300,300, QT: solidpattern );
}
Test result: the drawing area is completely transparent. Controls in the drawn area do not affect the controls.
The above methods are used well on Windows Vista and Ubuntu 9.10.
For more information, see the help document of QT qwidget.