From 68266eae2e43886be7ff4a16f5575ca036e539b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Mon, 22 Nov 2010 10:20:15 +0100
Subject: [PATCH] Fixed visible wrap column on systems with non-fractional
 fonts sizes

QFontMetricsF::averageCharWidth seems to always return a fractional size
(at least on Linux/GNOME with DejaVu Mono), even when the font is not
actually drawn at sub-pixels. This caused the visible wrap column to
appear in the wrong place.

As a workaround, use the width of the character 'x', which is pretty
average and does align to pixels when needed.

Task-number: QTCREATORBUG-2746
Reviewed-by: con
---
 src/plugins/texteditor/basetexteditor.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index e729431e76f..5e4092d1c0e 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -2814,7 +2814,9 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
     qreal lineX = 0;
 
     if (d->m_visibleWrapColumn > 0) {
-        lineX = QFontMetricsF(font()).averageCharWidth() * d->m_visibleWrapColumn + offset.x() + 4;
+        // Don't use QFontMetricsF::averageCharWidth here, due to it returning
+        // a fractional size even when this is not supported by the platform.
+        lineX = QFontMetricsF(font()).width(QLatin1Char('x')) * d->m_visibleWrapColumn + offset.x() + 4;
 
         if (lineX < viewportRect.width()) {
             const QBrush background = d->m_ifdefedOutFormat.background();
-- 
GitLab