Qt技巧:让Qt支持Win7的Aero和毛玻璃效果

4 篇文章 0 订阅

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       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值