I have a frameless QQuickWindow, and I want to move it with the mouse by dragging. Before trying in my big application, I have created a simple test application to try what I found here, using cursor position from C++ class to avoid problems from QML:
http://www.tickanswer.com/solved/539...jiggles-in-qml

But I failed with the code below. When I press over the red RECT and move the mouse, my yellow rect (root RECT) moves, but only inside the original size it had (in this case, 500x500)... What am I doing wrong?

Thanks in advance


In my main.cpp:
Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QtQuickControlsApplication a(argc, argv);
  4.  
  5. QQuickView* pView = new QQuickView();
  6.  
  7. CursorPosProvider mousePosProvider;
  8. pView->rootContext()->setContextProperty("mousePosition", &mousePosProvider);
  9. pView->setSource(QUrl("qrc:/Test.qml"));
  10. pView->setFlags(Qt::FramelessWindowHint);
  11. pView->show();
  12.  
  13. return a.exec();
  14. }
To copy to clipboard, switch view to plain text mode 
Test.qml:

Qt Code:
  1. import QtQuick 2.0
  2.  
  3. Rectangle {
  4. id: myWindow
  5. width: 500; height: 500
  6. color: "yellow"
  7.  
  8. Rectangle {
  9. anchors.centerIn: parent
  10. width: 200; height: 200
  11.  
  12. color: "red"
  13.  
  14. MouseArea {
  15. id: titleBarMouseRegion
  16. property var clickPos
  17. anchors.fill: parent
  18.  
  19. onPressed: clickPos = { x: mousePosition.cursorPos().x, y: mousePosition.cursorPos().y }
  20.  
  21. onPositionChanged: {
  22. myWindow.x = mousePosition.cursorPos().x - clickPos.x
  23. myWindow.y = mousePosition.cursorPos().y - clickPos.y
  24. }
  25. }
  26. }
  27. }
To copy to clipboard, switch view to plain text mode 

cursorprovider.h:

Qt Code:
  1. #ifndef CURSORPOSPROVIDER_H
  2. #define CURSORPOSPROVIDER_H
  3.  
  4. #include <QObject>
  5. #include <QPointF>
  6. #include <QCursor>
  7.  
  8. class CursorPosProvider : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit CursorPosProvider(QObject *parent = nullptr) : QObject(parent)
  13. {
  14. }
  15. virtual ~CursorPosProvider() = default;
  16.  
  17. Q_INVOKABLE QPointF cursorPos()
  18. {
  19. return QCursor::pos();
  20. }
  21. };
  22.  
  23. #endif // CURSORPOSPROVIDER_H
To copy to clipboard, switch view to plain text mode