QML如何将列表标题的字体大小设置为一致的值

时间:2018-10-29 18:22:34

标签: qt qml qtquick2

我正在尝试将header中的ListView设置为一致的font大小。鉴于我还需要它根据容器的heightwidth自动增长,如何获得美观的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);

enter image description here

0 个答案:

没有答案