另一个有趣的效果是辉光。 它呈现源元素的彩色和模糊副本。 游戏的一个示例用例是突出显示用户界面的某些部分 - 您可以通过使元素定期闪烁来将用户的注意力引导到元素(例如,按钮或徽章)上
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
Badge.qml
import QtQuick 2.0
Text {
text: qsTr("Attention!")
font.pointSize: 42
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Badge {
id: importantBadge
anchors.centerIn: parent
}
Glow {
source: importantBadge
anchors.fill: source
samples: 64
color: "red"
SequentialAnimation on radius {
loops: Animation.Infinite
running: true
NumberAnimation { from: 0; to: 30; duration: 500 }
PauseAnimation { duration: 100 }
NumberAnimation { from: 30; to: 0; duration: 500 }
PauseAnimation { duration: 1000 }
}
}
}