Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick2 help needed with dragging frameless window. [ solved ]
Forum Updated to NodeBB v4.3 + New Features

QtQuick2 help needed with dragging frameless window. [ solved ]

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    majster
    wrote on last edited by
    #1

    Hi!

    I'm looking for a way of dragging frameless window in QtQuick2.
    I fallowed this thread on the forum "Link":http://qt-project.org/forums/viewthread/5365/ but it giving me an error.

    Main different in the code is that my code uses QtQuick2ApplicationViewer instead of QmlApplicationViewer and it looks like QtQuick2ApplicationViewer do not have “.pos” property.

    This is my main.cpp

    @
    #include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"
    #include <QQmlContext>

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer);
    viewer.setFlags(Qt::FramelessWindowHint);
    viewer.setMainQmlFile&#40;QStringLiteral("qml/ubusell/main.qml"&#41;&#41;;
    viewer.showExpanded();
    
    return app.exec&#40;&#41;;
    

    }

    @

    This is part of my main.qml
    @
    MouseArea {
    id: mouseRegion
    anchors.fill: parent;
    property variant clickPos: "1,1"

                onPressed: {
                    clickPos  = Qt.point(mouse.x,mouse.y)
                }
    
                onPositionChanged: {
                    var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                    print(QmlApplicationViewer.pos)
                    QmlApplicationViewer.pos = (20,20)
                    QmlApplicationViewer.pos = Qt.point(QmlApplicationViewer.pos.x+delta.x,
                                      QmlApplicationViewer.pos.y+delta.y)
                }
        }
    

    @

    When I try to drag window I get this error:
    @TypeError: Cannot read property 'x' of undefined@

    Any ideas ?
    Is it even possible with QtQuick2 ?
    Thanks for help!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      majster
      wrote on last edited by
      #2

      dump

      1 Reply Last reply
      0
      • M Offline
        M Offline
        majster
        wrote on last edited by
        #3

        If anyone will approached the same problem here is a solution:

        source: "http://stackoverflow.com/questions/18927534/qtquick2-dragging-frameless-window-solved":http://stackoverflow.com/questions/18927534/qtquick2-dragging-frameless-window-solved

        @
        property variant clickPos: "1,1"

            onPressed: {
                clickPos  = Qt.point(mouse.x,mouse.y)
            }
        
            onPositionChanged: {
                var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                rootWindow.x = rootWindow.x+delta.x;
                rootWindow.y = rootWindow.y+delta.y;
            }
        

        @

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bobweaver
          wrote on last edited by
          #4

          why not just use drag ?
          @Rectangle{
          id: someElement
          ...
          ...
          MouseArea{
          id: foo
          anchors.fill: someElement
          drag.target: someElement
          drag.axis: XandYAxis
          }
          }@

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved