QML:将矩形移到 window 之外
QML: Move the rectangle outside the window
是否可以将矩形移到 window 之外?我唯一想到的是编写自定义逻辑,在将矩形移到 window.
之外时调整顶部 window 的大小
当前行为 (imgur .gif):
Current behavior
期望的行为 (imgur .png):
Desired behavior
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
id: root
width: 300
height: 500
visible: true
flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WA_TranslucentBackground
color: "#00000000"
Rectangle {
id: draggable
color: "blue"
x: 100
y: 100
width: 100
height: 100
MouseArea {
anchors.fill: parent
property real lastMouseX: 0
property real lastMouseY: 0
onPressed: {
lastMouseX = mouseX
lastMouseY = mouseY
}
onMouseXChanged: {
draggable.x += (mouseX - lastMouseX)
}
onMouseYChanged: {
draggable.y += (mouseY - lastMouseY)
}
}
}
Rectangle {
color: "blue"
x: 100
y: 300
width: 100
height: 100
// ...
}
}
Windows可以是其他Windows的children。 Window 行为仍受制于某些 platform-dependent 行为,但在桌面环境中 child Windows 仍应能够移出 parent Window.因此,只需将 Rectangle 更改为 Window 即可获得所需的效果。
Window {
id: root
Window {
id: draggable
...
}
}
是否可以将矩形移到 window 之外?我唯一想到的是编写自定义逻辑,在将矩形移到 window.
之外时调整顶部 window 的大小当前行为 (imgur .gif):
Current behavior
期望的行为 (imgur .png):
Desired behavior
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
id: root
width: 300
height: 500
visible: true
flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WA_TranslucentBackground
color: "#00000000"
Rectangle {
id: draggable
color: "blue"
x: 100
y: 100
width: 100
height: 100
MouseArea {
anchors.fill: parent
property real lastMouseX: 0
property real lastMouseY: 0
onPressed: {
lastMouseX = mouseX
lastMouseY = mouseY
}
onMouseXChanged: {
draggable.x += (mouseX - lastMouseX)
}
onMouseYChanged: {
draggable.y += (mouseY - lastMouseY)
}
}
}
Rectangle {
color: "blue"
x: 100
y: 300
width: 100
height: 100
// ...
}
}
Windows可以是其他Windows的children。 Window 行为仍受制于某些 platform-dependent 行为,但在桌面环境中 child Windows 仍应能够移出 parent Window.因此,只需将 Rectangle 更改为 Window 即可获得所需的效果。
Window {
id: root
Window {
id: draggable
...
}
}