对接QtQuick

Docking in QtQuick

据我了解,QtQuick 中没有内置可停靠容器的功能。我找到了一些来源,其中添加了这个,但是我无法决定要走哪条路。

https://developer.blackberry.com/native/documentation/dev/custom_components/index.html

How to get a QMainWindow from ApplicationWindow QML file to allow use of QDockWidget with QML files

有人可以推荐一种方法(或者最好是库)来为 QtQuick 添加对接吗?

我找到了一个适用于多个 windows 的解决方案,将小部件从主 window(停靠状态)移动到新的 window(未停靠状态)。

希望这对其他人有用这里是一个完整的例子:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Window 2.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Window {
        width: 100;
        height: 100;
        visible: false;
        id: wnd

        Rectangle {
            id: greenRect
            anchors.fill: parent
        }

        onClosing: {
            blueRect.state = "docked"
        }

    }

    Item {
        width: 200; height: 100

        Rectangle {
            id: redRect
            anchors.fill: parent
        }

        Rectangle {
            id: blueRect
            width: 50; height: 50
            x: 10; y: 10;
            color: "blue"

            states: [
                State {
                    name: "undocked"
                    ParentChange { target: blueRect; parent: greenRect; x: 10; y: 10 }
                },
                State {
                    name: "docked"
                    ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }
                }
            ]

            MouseArea {
                anchors.fill: parent;
                onClicked: {
                    blueRect.state = "undocked"
                    wnd.visible = true
                }
            }
        }
    }
}