diff options
author | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2016-02-02 14:53:01 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2016-02-23 13:57:08 +0000 |
commit | 2b03ab642329d2498eafa35ae7159991db5791e4 (patch) | |
tree | a32cf55e5f5ef02da0ff651deb44283d62ff24d5 /tests/auto/quick/qquickapplication | |
parent | 72447b6dbf98ace65ec46559337243970a668d26 (diff) |
Expose Qt.application.font
This is useful in order to specify font sizes that are some multiple of
the default size (which is almost always guaranteed to be a sensible,
legible size). For example:
Text {
text: "Large text"
font.pixelSize: Qt.application.font.pixelSize * 2
}
Other options are:
- "<h3>Large text</h3>" - adds extra space below the text since it's a
HTML element, so not really useful if you want a decent layout.
- Hard-coding a pixel size. Works OK when used in combination with
Qt::AA_EnableHighDpiScaling, and so long as you guess the correct size
that works for each device/display you're targeting. Doesn't work
without setting Qt::AA_EnableHighDpiScaling.
- Using FontMetrics/TextMetrics. Works fine, but is a bit verbose.
- Use an empty Text element. Creates an unnecessary item. Was
superseded by FontMetrics/TextMetrics.
- defaultPixelSize/implicitPixelSize and
defaultPointSize/implicitPointSize. There are already font-related
properties outside of the font grouped property, so this wouldn't be
out of place, but the API is already quite large.
[ChangeLog][QtQuick] Added Qt.application.font property.
Change-Id: I2d0899f2a6b717aab9afcea59f42fbf3715d8406
Task-number: QTBUG-50298
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquickapplication')
-rw-r--r-- | tests/auto/quick/qquickapplication/tst_qquickapplication.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index 1bd163fc4a..114f906736 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -47,6 +47,7 @@ private slots: void active(); void state(); void layoutDirection(); + void font(); void inputMethod(); void styleHints(); void cleanup(); @@ -196,6 +197,21 @@ void tst_qquickapplication::layoutDirection() QCOMPARE(Qt::LayoutDirection(item->property("layoutDirection").toInt()), Qt::LeftToRight); } +void tst_qquickapplication::font() +{ + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0; Item { property font defaultFont: Qt.application.font }", QUrl::fromLocalFile("")); + QQuickItem *item = qobject_cast<QQuickItem *>(component.create()); + QVERIFY(item); + QQuickView view; + item->setParentItem(view.rootObject()); + + QVariant defaultFontProperty = item->property("defaultFont"); + QVERIFY(defaultFontProperty.isValid()); + QCOMPARE(defaultFontProperty.type(), QVariant::Font); + QCOMPARE(defaultFontProperty.value<QFont>(), qApp->font()); +} + void tst_qquickapplication::inputMethod() { // technically not in QQuickApplication, but testing anyway here |