本页内容

Overlay QML Type

用于弹出窗口的窗口覆盖层。更多...

Import Statement: import QtQuick.Controls
Inherits:

Item

附加属性

附加信号

详细说明

“叠加层”为弹出窗口提供了一个显示层,确保弹出窗口显示在其他内容之上,并在modal 或dimmed 弹出窗口可见时将背景变暗。

该覆盖层是一个覆盖整个窗口的普通项(Item)。它可作为视觉父级,用于在场景坐标系中定位弹出窗口。

以下示例利用附加的Overlay.overlay 属性,将弹出窗口定位在窗口中央,无论打开该弹出窗口的按钮位于何处:

Button {
    onClicked: popup.open()

    Popup {
        id: popup

        parent: Overlay.overlay

        x: Math.round((parent.width - width) / 2)
        y: Math.round((parent.height - height) / 2)
        width: 100
        height: 100
    }
}

另请参阅 ApplicationWindow 。

附加属性文档

此附加属性包含一个组件,可作为视觉元素使用,用于实现模态弹出窗口的背景变暗效果。该组件专为可见的模态弹出窗口创建,并堆叠在这些弹出窗口下方。

该属性可附加到任何弹出窗口上。

例如,要更改模态弹出窗口的背景暗化颜色,可以使用以下代码:

Popup {
    id: popup
    width: 400
    height: 400
    modal: true
    visible: true

    Overlay.modal: Rectangle {
        color: "#aacfdbe7"
    }
}

另请参阅 Popup::modal 。

Overlay.modeless : Component [attached]

此附加属性包含一个组件,可作为视觉元素使用,用于为非模态弹出窗口实现背景变暗效果。该组件专为可见的变暗弹出窗口创建,并堆叠在这些弹出窗口下方。

该属性可附加到任何弹出窗口上。

例如,要更改非模态弹出窗口的背景变暗颜色,可以使用以下代码:

Popup {
    id: popup
    width: 400
    height: 400
    dim: true
    visible: true

    Overlay.modeless: Rectangle {
        color: "#aacfdbe7"
    }
}

另请参阅 Popup::dim 。

Overlay.overlay : Overlay [read-only attached]

此附加属性用于存储窗口叠加项。

该属性可附加到任何项、弹出窗口或窗口上。当附加到项或弹出窗口时,如果该项或弹出窗口不在窗口中,则其值为 `null `。

附加信号文档

[attached] pressed()

当弹出窗口可见时,如果用户点击了覆盖层,就会触发此附加信号。

该信号可附加到任何项目、弹出窗口或窗口上。当附加到项目或弹出窗口时,只有当该项目或弹出窗口位于窗口内时,该信号才会被触发。

注意:自 Qt 6.9起 ,右键点击时不会发出此信号。请改用将TapHandler 附加到覆盖层上。

注意: 相应的处理程序 是onPressed 。

[attached] released()

当弹出窗口可见时,如果用户释放了覆盖层,则会触发此附加信号。

该信号可附加到任何项目、弹出窗口或窗口上。当附加到项目或弹出窗口时,只有当该项目或弹出窗口位于某个窗口内时,该信号才会发出。

注意:自 Qt 6.9 起,右键点击时不会发出此信号。请改用将TapHandler 作为父对象的信号。

注意: 对应的处理程序 是onReleased 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.