gpt4 book ai didi

qt - 在 QtQuick 中停靠

转载 作者:行者123 更新时间:2023-12-05 00:53:20 25 4
gpt4 key购买 nike

关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




据我了解,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 添加对接吗?

最佳答案

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

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

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
}
}
}
}
}

关于qt - 在 QtQuick 中停靠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41490652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com