Transparency settings for QT form controls (three methods)

Source: Internet
Author: User

    1. Entire form

When you set up the Qt form (Qmainwindow, Qdialog), use the

[CPP]View PlainCopy
    1. 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
    1. Qgraphicsopacityeffect *opacityeffect=New Qgraphicsopacityeffect;
    2. Targetelement->setgraphicseffect (Opacityeffect);
    3. 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
    1. Draw a translucent rounded rectangle
    2. Qpainter *painter = new Qpainter (this);
    3. Painter->setpen (Qt::nopen);
    4. Painter->setbrush (Qcolor (0,170,255,100)); //Last item for transparency
    5. Painter->setopacity (0.6);
    6. Painter->drawroundrect (0,0,100,100,10,10); //Draw rounded rectangles

[CPP]View PlainCopy
    1. Sets the background color of a control to translucent
    2. Qwidget *widget = new Qwidget; Qwidget can be any qwidget-derived control
    3. Widget->setautofillbackground (true);
    4. Qpalette Palette;
    5. Palette.setcolor (Qpalette::background, Qcolor (192,253,123,100)); //Last item for transparency
    6. Palette.setbrush (Qpalette::background, Qbrush (Qpixmap (":/background.png"));
    7. Widget>setpalette (palette);
    8. 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)

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.