Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 137

How to set the font size of a list header to a consistent value

$
0
0

I am trying to set the header of a ListView to a consistent font sizes. Given that I also need it to automatically grow based on the height and width of the container, how can I achieve a good-looking header row?

What I tried already is the below. One way of solving this is not to set the width of each Text the same way and give different preferredWidth to each based on the string length.

BUT, what if my string is dynamically loaded, and I don't know how long my string would be. What is a good way of achieving a good-looking header instead of the one I have.

import QtQuick 2.4import QtQuick.Window 2.2import QtQuick.Layouts 1.2Window {    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        }    }}

enter image description here


Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>