Qwidget background (transparent)

Source: Internet
Author: User
1. Set the background to black and the foreground color to white.

Method 1: The paltette method is used. This method does not affect other control elements. We recommend that you use qpalette bgpal = palette ();
Bgpal. setcolor (qpalette: Background, qcolor (0, 0, 0,255 ));
// Bgpal. setcolor (qpalette: Background, QT: transparent );
Bgpal. setcolor (qpalette: foreground, qcolor (255,255,255,255); setpalette (bgpal );
Method 2: stylesheet method:
Setstylesheet ("background-color: RGB (255,255,255, 0); color: RGB );");
The method for sub-control components is as follows:
Setstylesheet ("Venus -- titlebar {background-color: RGB (255,255,255, 0); color: RGB );}");
Ii. Use stylesheet for the angular Control Element
Setstylesheet ("border: 2px groove gray; border-radius: 10px; padding: 2px 4px ;");
3. Corner Stone window roundrectwin: roundrectwin () {qpalette P = palette (); qpixmap IMG ("roundrect.png ");
Qbitmap mask ("roundrect_mask.png ");
P. setbrush (qpalette: window, qbrush (IMG ));
Setpalette (P );
Setmask (mask );
Resize (IMG. Size ());
// Setwindowflags (QT: framelesswindowhint); // This sentence removes the topic column.} note: the multi-clip part of the mask is set to white.
4. transparent window
1. The entire window is transparent, but the control elements on the window are not transparent. By setting the background color of the window, set the background color to completely transparent. Qpalette pal = palette ();
Pal. setcolor (qpalette: Background, qcolor (0x00, 0xff, 0x00,0x00); setpalette (PAL); effect:
The problem column of the window is not passed through;
The control elements in the user area of the window are not passed through. The qlabel control elements only follow the word to control the background color of the elements. The user area of the window is completely transparent.
In addition, the method shown on the webpage is setattribute (QT: wa_translucentbackground, true). The result of the preceding method is similar to that of the preceding method, however, sometimes the window is marked with colored spots and the cause is not found.
2. The ceiling window and its control components are completely transparent:
Setwindowopacity (0.7)
Effect: the window and control elements are completely transparent. Note that it cannot parse setwindowflags (QT: framelesswindowhint); otherwise, it will not work.
3. The entire window is not passed through, and the local window is partial:
In the paint event, use the clear-type Parallel coloring algorithm.
Void testwindow: paintevent (qpaintevent *)
{Qpainter P (this );
P. setcompositionmode (qpainter: compositionmode_clear); p. fillrect (10, 10,300,300, QT: solidpattern );}
Effect: The region is fully transparent. If a control element exists in the graphic region, the control element is not affected.
The above examples are based on directfb's QTE multicast protocol. In Linux and Windows, the effect is slightly different. For example, if there are 3rd real-world windows instances, the graphic region is a black hole. If the window itself is half transparent, the content in the window is half transparent, not completely transparent.
5. Control the alpha of qpixmap
Qpixmap temp (pixmaptop. Size (); temp. Fill (QT: transparent );
Qpainter P (& temp );
P. setcompositionmode (qpainter: compositionmode_source );
P. drawpixmap (0, 0, pixmaptop );
P. setcompositionmode (qpainter: compositionmode_destinationin );
P. fillrect (temp. rect (), qcolor (0, 0, 0, alpha); // -- lable into foreground parts UI-> label-> setscaledcontents (true );
UI-> label-> setpixmap (temp );

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.