如何在QML中更新基于加载器的底部控件
How update bottom control based on loader in QML
我有一个主qml文件,其中包含顶部项目是一个矩形,中间项目是加载器,加载不同的qml文件和底部项目是一些文本。
基于加载器项目,我想要底部项目应该调整,我试图使用锚,但有些它不工作,有人可以解释我如何做到这一点。
下面是我的代码:main.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle{
anchors.fill: parent
Rectangle{
id: toprect
width: 100
height: 100
color: "green"
anchors.horizontalCenter: parent.horizontalCenter
}
Loader{
id: middlerect
anchors.top: toprect.bottom
source: "qrc:/new.qml"
}
Rectangle{
id: belowrect
anchors.top: middlerect.bottom
Text{
text: "Bottom"
}
}
}
}
new.qml
import QtQuick 2.0
import QtQuick.Controls 1.2
Item {
id: newid
Column{
spacing: 10
Rectangle{
width: 100
height: 50
color: "lightblue"
}
Rectangle{
width: 100
height: 50
color: "lightgreen"
}
}
}
问题:
底部项与中间项重叠
你的代码有两个问题:
- 你应该给下面的 设置一个高度和宽度
- 你应该给你的新高度和宽度。/ol>
试试这个:
main.qml
import QtQuick 2.3 import QtQuick.Controls 1.2 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle{ anchors.fill: parent Rectangle{ id: toprect width: 100 height: 100 color: "green" anchors.horizontalCenter: parent.horizontalCenter } Loader{ id: middlerect anchors.top: toprect.bottom source: "qrc:/new.qml" } Rectangle{ id: belowrect color:"yellow" width: childrenRect.width height: childrenRect.height anchors.top: middlerect.bottom Text{ id:text text: "Bottom" } } } }
new.qml
import QtQuick 2.0 import QtQuick.Controls 1.2 Item { id: newid width: childrenRect.width height: childrenRect.height Column{ spacing: 10 Rectangle{ width: 100 height: 50 color: "lightblue" } Rectangle{ width: 100 height: 50 color: "lightgreen" } } }
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 为什么这个加载函数只抓取文件中的第一件事?
- C++WIN32-将RTF数据加载到Rich Edit控件
- 使用OpenCV 2.4在MFC SDI视图或控件中加载图像
- 无法使用 CefSharp 嵌入式 Chromium 浏览器控件加载网页
- C++:关于加载 DLL 和调用函数的一件小事
- MFC C++WebBrowser控件从字符串加载HTML
- 如何在QML中更新基于加载器的底部控件
- 从Qt快速控件加载下一个屏幕/应用程序窗口
- 如果用UiBuilder创建,bada中的Web控件不会加载
- 无法在Windows CE 6中重新加载ActiveX控件
- 如何在Visual c++中同步一个进度控件和一组正在加载的对话框中的数据