讓Qt支持Win7的Aero和毛玻璃效果


Qt5增加了許多特性,其中 Qt Windows Extras 模塊就增加了對Win7 Aero 效果的支持。

官網的介紹如下:

Qt Windows Extras provide classes and functions that enable you to use miscellaneous Windows-specific functions. For example, you can convert Qt objects to Windows object handles and manipulate DWM glass frames.

 

In addition, you can use features introduced with Windows 7, such as Aero Peek, Jump Lists, a progress indicator on a taskbar button, or a thumbnail toolbar.


    現在我們將該模塊來實現Win7的Aero窗口。

步驟(1):在Qt工程中添加模塊:winextras
步驟(2):包含頭文件:<QtWin>

源代碼(從Qt5示例中截取來的):

  1. if (QtWin::isCompositionEnabled())                           //返回DWM組合狀態
  2. {
  3.    QtWin::extendFrameIntoClientArea(this, -1, -1, -1, -1);    //玻璃效果
  4.    setAttribute(Qt::WA_TranslucentBackground, true);         //半透明背景
  5.    setAttribute(Qt::WA_NoSystemBackground, false);           //禁用無背景
  6.    setStyleSheet("MusicPlayer { background: transparent; }");
  7. }
  8. else
  9. {
  10.    QtWin::resetExtendedFrame(this);
  11.    setAttribute(Qt::WA_TranslucentBackground, false);
  12.    setStyleSheet(QString("MusicPlayer { background: %1; }").arg(QtWin::realColorizationColor().name()));
  13. }


看效果:
                

參考:
http://qt-project.org/doc/qt-5/qtwinextras-index.html                  qtwinextras索引
http://qt-project.org/doc/qt-5/qtwinextras-overview.html           qtwinextras概述
http://qt-project.org/doc/qt-5/qtwin.html                                    QtWin API     

http://blog.csdn.net/jan5_reyn/article/details/39042197


免責聲明!

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



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM