我正在尝试将header
中的ListView
设置为一致的font
大小。鉴于我还需要它根据容器的height
和width
自动增长,如何获得美观的header
行?
我已经尝试过的是以下内容。解决此问题的一种方法是,不以相同的方式设置每个Text
的宽度,并根据字符串长度为每个preferredWidth
赋予不同的import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Layouts 1.2
Window {
visible: true
width: 400
height: 200
RowLayout {
anchors.fill: parent
Text {
text: qsTr("Short")
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 1
fontSizeMode: Text.HorizontalFit | Text.VerticalFit
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
minimumPointSize: 12
font.pointSize: 40
}
Text {
text: qsTr("Medium String")
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 1
fontSizeMode: Text.HorizontalFit | Text.VerticalFit
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
minimumPointSize: 12
font.pointSize: 40
}
Text {
text: qsTr("A much longer String")
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 1
fontSizeMode: Text.HorizontalFit | Text.VerticalFit
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
minimumPointSize: 12
font.pointSize: 40
}
Text {
text: qsTr("An absurdly and unecessary long String!!")
Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 1
fontSizeMode: Text.HorizontalFit | Text.VerticalFit
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
minimumPointSize: 12
font.pointSize: 40
}
}
}
。但是,如果我的字符串是动态加载的,而我不知道我的字符串会持续多久,该怎么办。有什么比我现有的标题更好的方法来获得漂亮的标题。谢谢。
const data = [{
id: 1,
productName: "1",
action: ''
}, {
id: 1,
productName: "2",
action: ''
}];
let out = data.map(({ action, ...rest }) => rest);
console.log(out);