Qt practical skills: the method for implementing window transparency and qt practical skills for implementing windows
Requirement
Write the self-painted control to make the control background transparent. The buttons on the control are not transparent and display the two button areas (use the QPainter rough self-painted button ).
Method 1
# If 1 // Method 1: set the overall transparency (including sub-controls, the background will be black after transparency) QGraphicsOpacityEffect * opacityEffect = new QGraphicsOpacityEffect; setGraphicsEffect (opacityEffect ); opacityEffect-> setOpacity (1.0); // opacityEffect-> setOpacity (0.5); // opacityEffect-> setOpacity (0.0); # endif
Method 2
# If 1 // Method 2: Set transparency (all transparent, including child Controls) setWindowOpacity (1); // setWindowOpacity (0.5); // setWindowOpacity (0); # endif
Method 3
# If 1 // method 3: Set the background color to transparent (the transparent part, click the mouse, and the mouse signal is passed to the bottom layer of the Z axis) setAttribute (Qt: WA_TranslucentBackground); # endif
Method 4
# If 1 // Method 4: Use the color palette to set the background (the transparent part can specify the color, but there is a black background color) QPalette palette; palette. setColor (QPalette: Background, QColor (0,255,); // The last item is transparency. // palette. setColor (QPalette: Background, QColor (0,127,); // The last item is transparency. // palette. setColor (QPalette: Background, QColor (, 0,); // The last item is transparency setPalette (palette); # endif