据我所知,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的对接吗?
答案 0 :(得分:5)
我找到了一个解决方案,可以使用多个窗口将窗口小部件从主窗口(停靠状态)移动到新窗口(未停靠状态)。
希望这对其他人有用,这是一个完整的例子:
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
}
}
}
}
}