由于Qt 5.10
,可以为Popup
元素设置Overlay
附加属性。这里有一个例子,https://doc.qt.io/qt-5/qml-qtquick-controls2-overlay.html#modal-attached-prop。对于需要更改Popup
的背景(将dim:
属性设置为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
区域。这就是我想要改变的。到目前为止我还没有找到任何有记录的方法。
发布于 2020-04-05 14:13:59
我建议你使用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查看弹出窗口及其布局,以便了解内容项与背景之间的问题在哪里。也许你的调光是在比内容更大的背景上做的。https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html
https://stackoverflow.com/questions/61035434
复制相似问题