
TextSize.qml
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.
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.
4 years ago
CHANGELOG
1.0 (2016-05-14) First version.
4 years ago
CHANGELOG
1.0 (2016-05-14) First version.
Please login or register to add a comment or rating