QML Overlay
时间: 2025-01-21 10:17:49 浏览: 67
### QML 中实现 Overlay 效果
在 QML 中,`Overlay` 类型用于创建覆盖层效果。当希望为模态弹出窗口设置背景遮罩时,可以通过 `Overlay.modal` 属性来指定自定义的视觉元素。
下面是一个具体的例子展示如何改变模态 `Popup` 的背景颜色:
```qml
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
Button {
text: "Open"
onClicked: popup.open()
}
Popup {
id: popup
x: 100
y: 100
width: 200
height: 300
modal: true
focus: true
// 使用 Overlay 创建半透明蓝色矩形作为背景遮罩
Overlay.modal: Rectangle {
color: "#800000ff" // 半透明深蓝
}
}
}
```
此代码片段展示了如何利用 `Rectangle` 组件配合 `Overlay.modal` 来生成一个带有特定颜色和不透明度的覆盖层[^2]。
对于更复杂的场景,比如想要应用模糊或其他图形特效到整个应用程序界面,则可以考虑结合 `QtGraphicalEffects` 模块中的组件如 `FastBlur` 或者 `GaussianBlur` 来增强用户体验[^1]。
阅读全文
相关推荐



















