Description: QML component to get real size of text. It is currently used in the "Take a break" QML plasmoid.
Description 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 } }
LICENSES
The license of this program is the GPLv3.Last changelog:
Ratings & Comments
0 Comments