[Interest] MouseArea failed to handle onPositionChanged to a frameless ApplicationWindow in Qt 5.2.1
Rutledge Shawn
Shawn.Rutledge at digia.com
Wed May 7 08:11:14 CEST 2014
On 7 May 2014, at 4:50 AM, Leslie Zhai wrote:
> Hi qt developers,
>
> I use MouseArea to act like DragArea to move the frameless
> ApplicationWindow in Qt5.2.1
> https://github.com/AOSC-Dev/QJade/blob/master/qml/DragArea.qml#L17
>
> But Window Cannot Be Moved Over the Borders the Screen
> https://github.com/AOSC-Dev/QJade/issues/5
>
> Please someone show me how to fix it, thanks a lot!
I was testing that a couple of years ago, as follows:
import QtQuick 2.1
import QtQuick.Window 2.0
Window {
id: window
visible: true
width: 100
height: 100
flags: Qt.FramelessWindowHint
Rectangle {
color: "steelblue"
anchors.top: parent.top
width: parent.width
height: 20
MouseArea {
anchors.fill: parent
property real lastMouseX: 0
property real lastMouseY: 0
onPressed: {
lastMouseX = mouseX
lastMouseY = mouseY
}
onMouseXChanged: window.x += (mouseX - lastMouseX)
onMouseYChanged: window.y += (mouseY - lastMouseY)
}
}
}
I can drag this across both monitors on a dual-head system, either OSX or Linux; and if I wrap your code into a standalone test, it also works:
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
id: rootWindow
visible: true
width: 100
height: 100
MouseArea {
cursorShape: Qt.ArrowCursor
anchors.fill: parent
property variant clickPos: "1, 1"
onPressed: {
cursorShape = Qt.SizeAllCursor
clickPos = Qt.point(mouse.x, mouse.y)
}
onPositionChanged: {
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
rootWindow.x += delta.x
rootWindow.y += delta.y
}
onExited: cursorShape = Qt.ArrowCursor
}
}
More information about the Interest
mailing list