【发布时间】:2017-02-26 16:17:27
【问题描述】:
我是 qml 的新手。
我开始使用自定义项目开发一个小应用程序。
当我尝试在应用程序anchor.top: first_item.bottom 中使用来定位自定义组件的矩形时,一个在另一个下方不起作用。
内容文件 main.qml:
import QtQuick 2.5
Item
{
id:main_screen
Rectangle
{
width: 300
height: 60
id: text_content
color: "DarkGray"
opacity: 0.9
border.color: "blue"
border.width: 3
radius: 5
z:6
Text {
id: titleText
width: parent.width
height: parent.height
font.pointSize: 20
font.family: "Arial"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "Test - title"
color: "White"; style: Text.Raised;
}
}
//..................This rectangle is shown below main_screen... so is OK
Custom_item
{
id:first_item
anchors.top: main_screen.bottom
}
//..................This rectangle is not shown below first_item... but it shown on absolute top, in overlap of retangle title
Custom_item
{
id:second_item
anchors.top: first_item.bottom
}
//..................This rectangle is not shown below second_item... but it shown on absolute top, in overlap of retangle title
Custom_item
{
id:third_item
anchors.top: second_item.bottom
}
}
内容文件Custom_item.qml
import QtQuick 2.5
Item
{
id:testComponent
Rectangle
{
width: 300
height: 60
id: text_content
color: "DarkGray"
opacity: 0.9
border.color: "blue"
border.width: 3
radius: 5
z:6
}
}
我做错了什么?
谢谢
【问题讨论】:
-
我建议也发布一个屏幕截图,而不是试图解释 ui 问题,即,而不是“此矩形未显示在 first_item 下方...但它显示在绝对顶部,与矩形重叠标题”一个截图可以节省一千个单词:)
-
它有一个 mcve,比千张图片更能解释问题。值得称道的第一篇文章!