[Interest] QML solution for fitting text?
Nurmi J-P
jpnurmi at theqtcompany.com
Tue Nov 17 19:42:44 CET 2015
> On 17 Nov 2015, at 19:32, Jason H <jhihn at gmx.com> wrote:
>
> I want to fit text into a rectangle, but dynamically size the text like scaling an image:
> Rectangle {
> width: // some with
> width: // some height
> Text { text: "Hello World"; anchors.fill: parent; font.pixelSize: ???<Dynamic> }
> }
See Text::fontSizeMode: http://doc.qt.io/qt-5/qml-qtquick-text.html#fontSizeMode-prop
> In the old QWidget days, I'd use QFontMetrics to figure out what size would fit. Has this been solved for QML?
There’s also FontMetrics (http://doc.qt.io/qt-5/qml-qtquick-fontmetrics.html) and TextMetrics (http://doc.qt.io/qt-5/qml-qtquick-textmetrics.html) in QML, but Text::fontSizeMode does the job for you.
--
J-P Nurmi
More information about the Interest
mailing list