Qt Components

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net


QML component to get real size of text.
It is currently used in the "Take a break" QML plasmoid.

This component (TextSize) obtains the real size (real width and real height) of a text component (Text, Label, PlasmaComponents.Label, etc).

The real size is obtained by using a modern component (TextMetrics) that is available only in QtQuick 2.5 or newer. If the user has an older version (QtQuick 2.0), then a classic component (Text) will be used instead, so the size obtained will not be so real, but it will work!

The adventage of using TextSize is that you will get a size as real as possible, and your program will work in both old and new versions of QtQuick, because they are detected automatically.

How to use
Just set the font and text properties, and you will get the real size (well, as real as possible) in the real_width and real_height properties.

Example of use

import QtQuick 2.0 // your program will work in QtQuick 2.0 or newer!
import lib // just put TextSize.qml into a lib subdir

Rectangle // an orange rectangle with the size of the_text
color: orange
width: t_size.real_width
height: t_size.real_height

Text // yellow text into the rectangle
id: the_text
text: Some text
color: yellow
anchors.centerIn: parent

TextSize // calculates the real size of the_text
id: t_size
font: the_text.font
text: the_text.text


The license of this program is the GPLv3.
Last changelog:

5 years ago

1.0 (2016-05-14) First version.

Be the first to comment

5 years ago

1.0 (2016-05-14) First version.

Be the first to comment
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
0 Affiliates
updated May 14 2016
added May 14 2016
downloads 24h
mediaviews 24h 0
pageviews 24h 2
System Tags