显示在同一行QML上的ListView
我尝试将ListView包装成矩形,但成功了,但现在我遇到了一个问题。标题行和代理行显示在同一行上,如下所示: 我希望它是这样的,但它不能滚动: 这是我的代码:显示在同一行QML上的ListView,listview,header,delegates,qml,Listview,Header,Delegates,Qml,我尝试将ListView包装成矩形,但成功了,但现在我遇到了一个问题。标题行和代理行显示在同一行上,如下所示: 我希望它是这样的,但它不能滚动: 这是我的代码: Rectangle { id:listViewRec visible: true anchors.fill: parent anchors.topMargin: 100 * wdw.height / 1080 anchors.bottomMargin: 30
Rectangle {
id:listViewRec
visible: true
anchors.fill: parent
anchors.topMargin: 100 * wdw.height / 1080
anchors.bottomMargin: 30 * wdw.height / 1080
anchors.leftMargin: 30 * wdw.width / 1920
anchors.rightMargin: 30 * wdw.width / 1920
ListView {
id: listViewDispInf
anchors.fill: parent
width: listViewRec.width
height: listViewRec.height
clip: true
orientation: ListView.Horizontal
flickableDirection: Flickable.HorizontalFlick
boundsBehavior: Flickable.StopAtBounds
model: batteries
header: Row {
function itemAt(index) { return repeater1.itemAt((index)) }
Repeater {
id: repeater1
model: Parameters { }
Rectangle {
height: 50 * wdw.height / 1080
width: 1.1 * txt1.paintedWidth
Text {
id: txt1
anchors.centerIn: parent
text: name
}
}
}
}
delegate : Row {
id: delegate
property var informations: model.modelData
function itemAt(index) { return repeater2.itemAt((index)) }
Repeater {
id: repeater2
model: 26
Rectangle {
height: (listViewRec.height - listViewDispInf.headerItem.itemAt(index).height ) / 6
width: listViewDispInf.headerItem.itemAt(index).width
Text {
anchors.centerIn: parent
text: delegate.informations.getInformations(index)
}
}
}
}
}
}
模型来自my main.cpp,如下所示:
QList<QObject *> dataList;
dataList.append(b1);
engine.rootContext()->setContextProperty("batteries", QVariant::fromValue(dataList));
QList数据列表;
数据表追加(b1);
engine.rootContext()->setContextProperty(“电池”,QVariant::fromValue(数据列表));
您没有为列表视图使用正确的值
您应该删除该行或使用orientation:ListView.Vertical
编辑:另外,看看你的代码,看起来你实际上是在寻找一个新的
您可以使用不同的列和方法,而不是使用行和计算每个项目的宽度。请提供一个列表。首先感谢您的回答。我尝试了你的答案,这是同一个问题,我的标题和代表在同一行。因此,我所有的ListView都在一行上。请提供一个。您的示例不完整且不可验证,我们没有足够的信息重现该问题。你的型号是什么?你的代表?我完成了我的示例代码,添加了一些屏幕和模式原点以便更好地解释。我仍然认为你的问题是水平方向。我用我自己的假ListModel和方向:ListView.Vertical
尝试了你的代码,效果很好。您指定了一个水平ListView,因此将它放在同一行上是预期的行为。而且看起来您是过于复杂的东西。以您为例,我认为TableView更合适。请参阅我编辑的答案。