6 years ago (2014-12-26)  Algorithm language |   First to comment  1259 
post score 0 times, average 0.0

For beginners of QT, removing the border and realizing the window transparency may be the basic requirements for beautifying the GUI. The author has synthesized the online code and summarized it:

Borderless (title bar) window

  setWindowOpacity(1) This code implements the transparent effect of the window. The parameters in the function are transparency, 1 means opacity setWindowFlags(Qt::FramelessWindowHint); hide the title bar and border of the window  

The background is painted black and the foreground is set to white.

Method one, the palmtette way, after testing, this method will not affect other controls, it is recommended to use  

  Method two, stylesheet methods Affect the child control method is:  

  The methods that do not affect child controls are:  


Rounded controls



  Rounded window 



Translucent window


  1. The overall window is transparent, but the controls on the form are opaque. By setting the background color of the form, set the background color to full transparency. Test effect: The form title bar is opaque; the controls on the form client area are opaque, the QLabel control is just a word display, and the control background color is transparent; the form client area is completely transparent. Also seen from the Internet: The result of the experiment was similar to the above method, but sometimes the form was filled with some variegated spots and no reason was found.
  2. The window and the controls on it are translucent: 
      Test effect: The windows and controls are translucent.Note that it is not possible to setWindowFlags(Qt::FramelessWindowHint);  
  3. The overall window is opaque, partially transparent: Use the Clear mode drawing in the Paint event.  
      Test effect: The drawing area is fully transparent.Controls are not affected if the drawing area has controls. The above experiments are based on the Qte test of Directfb.The effect will be slightly different under Linux and Windows. For example, in the third experiment under Windows, the drawing area is a black hole. If the Window itself is semi-permeable, it is the content of the Window plus the semi-transparent effect, not the full transparency effect.    

Control the QPixmap's alpha



 Layout boundaries



The above code is from the Internet and is published and published by myself. After the author's study, the dragging window code is issued.



This article has been printed on copyright and is protected by copyright law. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click on the "sponsored author" below to reward the author!

Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/getting-started-with-qt-how-to-write-without-borders-the-title-bar-of-windows-transparent-windows-round-controls-2.html

Post comment


No Comment


Forget password?