CentOS下Qt窗口透明效果失效,成黑色背景的問題


一、問題

       Linux系統下Qt窗口的透明效果成了黑色,但同樣的代碼在windows機子上有透明效果,主要是修改系統的配置,僅在centos6.3及其以上版本實驗過。其他系統可以相應配置。

 

二、問題運行圖

 

 

(1)Qt透明效果,centos下運行都會出現如下圖1所示。

 

 

三、解決方法

 

 

(1)窗口透明,窗口上的控件不透明,其代碼設置

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到我的代碼片
  1. setAutoFillBackground(false);  //這個不設置的話就背景變黑  
  2. setWindowFlags(Qt::FramelessWindowHint);  
  3. setAttribute(Qt::WA_TranslucentBackground,true);  
  4. //setWindowOpacity(1);  //窗口及控件都半透明,其取值為0-1(0是全透明,1是不透明)  
  5. //setAttribute(Qt::WA_NoSystemBackground, true);  
  6. //setStyleSheet("background-color:transparent;");  
  7. //QWidget::setAttribute(Qt::WA_NoBackground, true);  
  8. //QPalette pal = palette();   
  9. //pal.setColor(QPalette::Background, QColor(0x00,0xff,0x00,0x00));   
  10. //setPalette(pal);  

(2)Qt參考文檔

 

Platform notes:

  • X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.
  • Windows: The widget needs to have the Qt::FramelessWindowHintwindow flag set for the translucency to work.
平台注意事項:
       X11(linux):此特性依賴於能提供支持ARGB視覺效果和復合式視窗管理的X服務的功能開啟。
       Windows:此控件需要設置窗口標志 Qt::FramelessWindowHint才能開啟透明功能。
接着修改Centos的配置,是透明效果生效。
(3)修改Centos配置
進入菜單欄的系統->首選項->桌面效果
修改為Complz,不過修改后系統會變得稍微有些卡,太耗內存了。
改動后的效果(透明)(截圖的背景色是白色):

 

http://blog.csdn.net/taiyang1987912/article/details/37037657


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。