如何在 qt 快速应用程序中使窗格在顶部可见?
How make a pane visible on top in qt quick application?
我想显示一个消息栏以向用户显示我的消息,在所有其他 windows 和页面之上可见吗?
MessageBar.qml
Pane {
id: bar
z: 9999999999999999
property alias message:me
Message{
id: me
onContentChanged: {
}
}
Material.background: message.backColor
height: 48
Label{
color: "white"
text: message.content
anchors.fill: parent
horizontalAlignment: Label.AlignHCenter
}
property bool visibleState: message.visible&&message.messageType== Message.SimpleMessage
scale: visibleState?1.0:0.0
Behavior on scale {
NumberAnimation {
duration: 100
}
}
}
main.qml
ApplicationWindow {
MessageBar{
id: messageBar
anchors.centerIn: parent
Layout.fillWidth: true
}
}
但是在其他页面下是可见的怎么解决这个问题?
最简单的方法是使用 Popup
。默认情况下,这些显示在场景中的所有其他项目之上。此外,您可以设置弹出窗口的 z
值以确保它位于所有其他弹出窗口之上。
如果您出于某种原因不想使用弹出窗口,您可以将该项目添加到 overlay:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
ApplicationWindow {
width: 640
height: 480
visible: true
Button {
text: "Button"
}
Pane {
width: 200
height: 200
parent: Overlay.overlay
Material.background: Material.Grey
Label {
text: "Above"
anchors.centerIn: parent
}
}
}
我想显示一个消息栏以向用户显示我的消息,在所有其他 windows 和页面之上可见吗?
MessageBar.qml
Pane {
id: bar
z: 9999999999999999
property alias message:me
Message{
id: me
onContentChanged: {
}
}
Material.background: message.backColor
height: 48
Label{
color: "white"
text: message.content
anchors.fill: parent
horizontalAlignment: Label.AlignHCenter
}
property bool visibleState: message.visible&&message.messageType== Message.SimpleMessage
scale: visibleState?1.0:0.0
Behavior on scale {
NumberAnimation {
duration: 100
}
}
}
main.qml
ApplicationWindow {
MessageBar{
id: messageBar
anchors.centerIn: parent
Layout.fillWidth: true
}
}
但是在其他页面下是可见的怎么解决这个问题?
最简单的方法是使用 Popup
。默认情况下,这些显示在场景中的所有其他项目之上。此外,您可以设置弹出窗口的 z
值以确保它位于所有其他弹出窗口之上。
如果您出于某种原因不想使用弹出窗口,您可以将该项目添加到 overlay:
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
ApplicationWindow {
width: 640
height: 480
visible: true
Button {
text: "Button"
}
Pane {
width: 200
height: 200
parent: Overlay.overlay
Material.background: Material.Grey
Label {
text: "Above"
anchors.centerIn: parent
}
}
}