qt - QML如何将列表标题的字体大小设置为一致的值
问题描述
我正在尝试将header
a设置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
}
}
}
解决方案
推荐阅读
- reactjs - React Context 和 Apollo Client Link 之间的通信
- c++ - C ++ 14函数返回对象数组,尽管复制构造函数被删除
- reactjs - 使用 React + Material UI 创建自定义国家/地区选择
- performance - gstreamer 流的帧速率慢
- internet-explorer - Internet Explorer 在矩阵变换时扭曲 SVG 图像
- python - 从 Quora 问题中抓取答案仅返回 10 个答案
- reactjs - 如何用 jest 和 react-testing-library 测试 react-toastify
- amazon-web-services - 如何创建映射模板以将路径参数映射到 apigateway 中的 lambda 函数?
- python - 如何在 multiprocessing.Pool 中的函数运行中使用模拟
- typescript - Promise.then 回调中的打字稿错误