首页 > 解决方案 > 如何更改 QML ApplicationWindow Overlay 大小?

问题描述

因为可以为元素Qt 5.10设置Overlay附加属性。Popup这里有一个示例https://doc.qt.io/qt-5/qml-qtquick-controls2-overlay.html#modal-attached-prop。对于需要更改背景以Popupdim:属性设置为true. 但是(至少对我而言)我不知道如何更改Overlay大小。例如,我有一个自定义ApplicationWindow覆盖contents:属性能够在窗口上绘制阴影(我的自定义窗口没有边框)并放置MouseArea在边框之外以模仿本机窗口的行为。可悲的部分是 -Overlay绘制在整个窗口区域上,这使得超出边界的区域变得丑陋。

有谁知道在使用dim:属性时调整覆盖大小(我的意思是至少背景阴影)的方法Popup

这是一个典型的Popup代码:

Popup {
        id: popupReleaseNotes
        x: Math.round(parent.width/2 - width/2)
        y: Math.round(parent.height/2 - height/2)
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
        modal: true
        dim: true
    }

在这里你可以看到它在我的应用程序中的样子:

在此处输入图像描述

覆盖背景超出了我的自定义边界,这意味着它占据了所有ApplicationWindow区域。这就是我想要改变的。到目前为止,我没有找到任何记录的方式。

标签: qtpopupqmloverlayapplicationwindow

解决方案


我建议你使用 ColorOverlay。

https://doc.qt.io/qt-5/qml-qtgraphicaleffects-coloroverlay.html

无论如何,在我看来,您错过了 Overlay.Modal。阅读文档(),我期待的是:

Popup {
        id: popupReleaseNotes
        x: Math.round(parent.width/2 - width/2)
        y: Math.round(parent.height/2 - height/2)
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
        modal: true

        visible: true

        Overlay.modal: Rectangle {
               anchors.fill: parent
               color: "#aacfdbe7"
        }
}

PS 查看 Popup 及其布局,以了解可能是内容项与背景的问题。也许您的调光是在比内容更大的背景上完成的。 https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html


推荐阅读