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 /src | |
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 'src')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 5 | ||||
-rw-r--r-- | src/quick/util/qquickapplication.cpp | 5 | ||||
-rw-r--r-- | src/quick/util/qquickapplication_p.h | 3 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 0e99e4ca89..e989d37c6f 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -493,6 +493,10 @@ The following functions are also on the Qt object. from right to left. \endlist \row + \li \c application.font + \li This read-only property holds the default application font as + returned by \l QGuiApplication::font(). + \row \li \c application.arguments \li This is a string list of the arguments the executable was invoked with. \row @@ -531,6 +535,7 @@ The following functions are also on the Qt object. \li application.active \li application.state \li application.layoutDirection + \li application.font \endlist */ diff --git a/src/quick/util/qquickapplication.cpp b/src/quick/util/qquickapplication.cpp index a4e2f0eb0e..5c26b23ff7 100644 --- a/src/quick/util/qquickapplication.cpp +++ b/src/quick/util/qquickapplication.cpp @@ -90,4 +90,9 @@ Qt::ApplicationState QQuickApplication::state() const return QGuiApplication::applicationState(); } +QFont QQuickApplication::font() const +{ + return QGuiApplication::font(); +} + QT_END_NAMESPACE diff --git a/src/quick/util/qquickapplication_p.h b/src/quick/util/qquickapplication_p.h index 971c9a203a..091cb094ed 100644 --- a/src/quick/util/qquickapplication_p.h +++ b/src/quick/util/qquickapplication_p.h @@ -52,6 +52,7 @@ // #include <QtCore/QObject> +#include <QtGui/QFont> #include <qqml.h> #include <QtQml/private/qqmlglobal_p.h> #include <private/qtquickglobal_p.h> @@ -66,6 +67,7 @@ class Q_AUTOTEST_EXPORT QQuickApplication : public QQmlApplication Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection NOTIFY layoutDirectionChanged) Q_PROPERTY(bool supportsMultipleWindows READ supportsMultipleWindows CONSTANT) Q_PROPERTY(Qt::ApplicationState state READ state NOTIFY stateChanged) + Q_PROPERTY(QFont font READ font CONSTANT) public: explicit QQuickApplication(QObject *parent = 0); @@ -74,6 +76,7 @@ public: Qt::LayoutDirection layoutDirection() const; bool supportsMultipleWindows() const; Qt::ApplicationState state() const; + QFont font() const; Q_SIGNALS: void activeChanged(); |