From ff332335eae78d5de1e71e74a4322a253a80a9a5 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Mon, 18 Jun 2018 03:55:52 +0100 Subject: [PATCH] Improved font positioning in Qt backend --- backend_qt/qzint.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 46ac1611..4da613ce 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -17,6 +17,7 @@ #include "qzint.h" #include +#include namespace Zint { static const char* fontstyle = "Arial"; @@ -388,8 +389,12 @@ namespace Zint { if (string) { painter.setFont(fontLarge); } + QFontMetrics fm(fontLarge); while (string) { - painter.drawText(0.0, string->y, m_zintSymbol->vector->width, 7, Qt::AlignCenter, QString::fromUtf8((const char *) string->text, -1)); + QString content = QString::fromUtf8((const char *) string->text, -1); + int width = fm.width(content, -1); + int height = fm.height(); + painter.drawText(string->x - (width / 2.0), string->y - height, width, height, Qt::AlignHCenter | Qt::AlignBottom, content); string = string->next; }