在 QtQuick 中停靠 [英] Docking in QtQuick
问题描述
据我所知,QtQuick 中没有可停靠容器的内置功能.我找到了一些添加此内容的来源,但是我无法决定要走哪条路.
As far as I understand there is no built-in functionality for dockable containers in QtQuick. I found a few sources where this is added, however I am having trouble deciding which way to go.
https://developer.blackberry.com/native/documentation/dev/custom_components/index.html
如何从 ApplicationWindow QML 文件中获取 QMainWindow 以允许将 QDockWidget 与 QML 文件一起使用
有人可以推荐一种向 QtQuick 添加对接的方法(或者最好是库)吗?
Can someone recommend a way (or preferably a library) to add docking to QtQuick?
推荐答案
我找到了一个适用于多个窗口的解决方案,将小部件从主窗口(停靠状态)移动到新窗口(非停靠状态).
I found a solution that works with multiple windows moving a widget from the main window (docked state) to a new window (undocked state).
希望这对其他人有用这里是一个完整的例子:
Hoping that this is useful to others here is a complete example:
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
}
}
}
}
}
这篇关于在 QtQuick 中停靠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!