[Learning Record] Transparency settings for QT form controls

Source: Internet
Author: User

    1. 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

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.