Qt practical skills: the method for implementing window transparency and qt practical skills for implementing windows

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.