How align Listview's delegate text to customized title text?
Unsolved
QML and Qt Quick
-
import QtQuick 2.0 Item { id: root width: 1921 height: 1081 Column { x: 328 y: 184 Item { id: tableTitle width: 1593 height: 91 Text { id: ttWellId x: 90 y: 31 text: "Well ID" } Text { id: ttSample x: 276 y: 31 text: "Sample" } } ListView { width: 1593 height: 785 clip: true model: ListModel { ListElement{ name: "A1"; sample: "sample1"; } ListElement{ name: "A2"; sample: "sample2"; } } delegate: resultDelegate Component { id: resultDelegate Item { id: wellInfoItem height: 60 width: 1592 Text { text: name anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: ttWellId.horizontalCenter } Text { text: sample anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: ttWellId.horizontalCenter } } } } } }
I need
resultDelegate
's text align to text in thetableTitle
. Butanchors.horizontalCenter: ttWellId.horizontalCenter
's effect as following:
The effect I want is as follows :
please ignore the multiple row and focus on contents are aligned horizontally to the header. And I got a error hint:QML Text: Cannot anchor to an item that isn't a parent or sibling.
-
I have a solution, aligning field to header title and setting the same width, then we could set same alignment for
Text
item.
But my.qml
file from Qt Designer Stutido, They had been given in the form of fixed coordinates at most of the time, adjusting for my solution is too terrible.