TextSize.qml

Qt Components

Source i (link to git-repo or to original if based on someone elses unmodified work):

Add the source-code for this project on opencode.net

0
Become a Fan
5.0

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:

CHANGELOG
1.0 (2016-05-14) First version.


Ratings & Comments

0 Comments

Be the first to comment
Pling
0 Affiliates
Details
license
version 1.0
updated
added
downloads 24h 0
mediaviews 24h 0
pageviews 24h 0

Other Qt Components:

QyurVisualSqlFilter
purser79
last update date: 7 years ago

Score 5.0

QyurSqlTreeView
purser79
last update date: 7 years ago

Score 6.5

QtBasic
mantur
last update date: 12 years ago

Score 5.0

up2Date
seanpatti
last update date: 9 years ago

Score 5.0

MStyles
mchara
last update date: 16 years ago

Score 5.0

Hdr reading plugin
mchara
last update date: 16 years ago

Score 5.0