发现Win7的Areo界面效果很好看,饶有兴致的百度了下Qt的实现方式,终于知道了简单的实现方式,以下简单介绍下。
官方地址:http://doc.qt.io/qt-5/examples-qtwinextras.html
官方的例程是有介绍的,具体实现是在窗口类中添加函数:
-
void Window::stylize()
{
if (QtWin::isCompositionEnabled()) {
QtWin::extendFrameIntoClientArea(this, -1, -1, -1, -1);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_NoSystemBackground, false);
setStyleSheet("Window { background: transparent; }");
} else {
QtWin::resetExtendedFrame(this);
setAttribute(Qt::WA_TranslucentBackground, false);
setStyleSheet(QString("Window { background: %1; }").arg(QtWin::realColorizationColor().name()));
}
}
-
添加函数: bool Window::event(QEvent *event)
{
if (event->type() == QWinEvent::CompositionChange || event->type() == QWinEvent::ColorizationChange)
stylize();
return QWidget::event(event);
}
-
在类内添加 #include
-
在.pro中添加 QT += winextras