summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2017-08-02 11:39:01 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2017-12-08 15:06:32 +0000
commit4d88d79aa507777bce40740b21747f656efc074d (patch)
tree0b335cac61062eaf281b5a76514f8bd74bbcaaf2 /examples/widgets
parentcd56e843cc53938111879c21570eaf8225719743 (diff)
Update usage of QFontMetrics::width() to new API
QFontMetrics(F)::width() has been deprecated and is replaced by horizontalAdvance(). This updates all usage of it in tests and documentation. It is worth noting that many or most of the usages of QFontMetrics::width() probably intended to use boundingRect().width(), but since it currently works, I have not looked into that, just replaced the function name mechanically. Change-Id: Iec382e5bad0b50f37a6cfff841bfb46ed4d4555f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/src/wiggly.qdoc8
-rw-r--r--examples/widgets/effects/fademessage/fademessage.cpp2
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp2
-rw-r--r--examples/widgets/painting/shared/arthurstyle.cpp4
-rw-r--r--examples/widgets/statemachine/rogue/window.cpp4
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp2
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.cpp2
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.cpp4
8 files changed, 14 insertions, 14 deletions
diff --git a/examples/widgets/doc/src/wiggly.qdoc b/examples/widgets/doc/src/wiggly.qdoc
index f330b016df..d70d609e2b 100644
--- a/examples/widgets/doc/src/wiggly.qdoc
+++ b/examples/widgets/doc/src/wiggly.qdoc
@@ -143,10 +143,10 @@
position on the wiggly line based on \c step. In addition, \c x
is incremented by the character's width.
- For simplicity, we assume that QFontMetrics::width(\c text)
- returns the sum of the individual character widths
- (QFontMetrics::width(\c text[i])). In practice, this is not
- always the case because QFontMetrics::width(\c text) also takes
+ For simplicity, we assume that QFontMetrics::horizontalAdvance(\c text)
+ returns the sum of the individual character advances
+ (QFontMetrics::horizontalAdvance(\c text[i])). In practice, this is not
+ always the case because QFontMetrics::horizontalAdvance(\c text) also takes
into account the kerning between certain letters (e.g., 'A' and
'V'). The result is that the text isn't perfectly centered. You
can verify this by typing "AVAVAVAVAVAV" in the line edit.
diff --git a/examples/widgets/effects/fademessage/fademessage.cpp b/examples/widgets/effects/fademessage/fademessage.cpp
index d91293288c..9943147bb7 100644
--- a/examples/widgets/effects/fademessage/fademessage.cpp
+++ b/examples/widgets/effects/fademessage/fademessage.cpp
@@ -108,7 +108,7 @@ void FadeMessage::setupScene()
int fh = fontMetrics.height();
QString sceneText = "Qt Everywhere!";
- int sceneTextWidth = fontMetrics.width(sceneText);
+ int sceneTextWidth = fontMetrics.horizontalAdvance(sceneText);
QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
block->setPen(Qt::NoPen);
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
index 3f72a33902..490a8508d6 100644
--- a/examples/widgets/painting/deform/pathdeform.cpp
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -364,7 +364,7 @@ void PathDeformRenderer::setText(const QString &text)
path.addText(advance, f, text.mid(i, 1));
m_pathBounds |= path.boundingRect();
m_paths << path;
- advance += QPointF(fm.width(text.mid(i, 1)), 0);
+ advance += QPointF(fm.horizontalAdvance(text.mid(i, 1)), 0);
}
} else {
QPainterPath path;
diff --git a/examples/widgets/painting/shared/arthurstyle.cpp b/examples/widgets/painting/shared/arthurstyle.cpp
index 484eaec31c..f4fc76bda6 100644
--- a/examples/widgets/painting/shared/arthurstyle.cpp
+++ b/examples/widgets/painting/shared/arthurstyle.cpp
@@ -294,7 +294,7 @@ void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
QPixmap titleRight = cached(":res/images/title_cap_right.png");
QPixmap titleStretch = cached(":res/images/title_stretch.png");
- int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
+ int txt_width = groupBox->fontMetrics.horizontalAdvance(groupBox->text) + 20;
painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
painter->drawTiledPixmap(tileRect, titleStretch);
@@ -385,7 +385,7 @@ QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComp
QPixmap titleLeft = cached(":res/images/title_cap_left.png");
QPixmap titleRight = cached(":res/images/title_cap_right.png");
QPixmap titleStretch = cached(":res/images/title_stretch.png");
- int txt_width = group->fontMetrics.width(group->text) + 20;
+ int txt_width = group->fontMetrics.horizontalAdvance(group->text) + 20;
rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
txt_width - titleLeft.width() - titleRight.width(),
titleStretch.height());
diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp
index 3515138382..059fbf1003 100644
--- a/examples/widgets/statemachine/rogue/window.cpp
+++ b/examples/widgets/statemachine/rogue/window.cpp
@@ -98,7 +98,7 @@ void Window::paintEvent(QPaintEvent * /* event */)
QFontMetrics metrics(font());
QPainter painter(this);
int fontHeight = metrics.height();
- int fontWidth = metrics.width('X');
+ int fontWidth = metrics.horizontalAdvance('X');
int yPos = fontHeight;
int xPos;
@@ -177,7 +177,7 @@ QSize Window::sizeHint() const
{
QFontMetrics metrics(font());
- return QSize(metrics.width('X') * WIDTH, metrics.height() * (HEIGHT + 1));
+ return QSize(metrics.horizontalAdvance('X') * WIDTH, metrics.height() * (HEIGHT + 1));
}
//![2]
diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
index 55d45501f1..5bab921516 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.cpp
+++ b/examples/widgets/widgets/charactermap/characterwidget.cpp
@@ -181,7 +181,7 @@ void CharacterWidget::paintEvent(QPaintEvent *event)
if (key == lastKey)
painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));
- painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2,
+ painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.horizontalAdvance(QChar(key))/2,
row*squareSize + 4 + fontMetrics.ascent(),
QString(QChar(key)));
}
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.cpp b/examples/widgets/widgets/codeeditor/codeeditor.cpp
index 69974e72be..7e56a75294 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/widgets/codeeditor/codeeditor.cpp
@@ -79,7 +79,7 @@ int CodeEditor::lineNumberAreaWidth()
++digits;
}
- int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
+ int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
return space;
}
diff --git a/examples/widgets/widgets/wiggly/wigglywidget.cpp b/examples/widgets/widgets/wiggly/wigglywidget.cpp
index 9dfd43ff77..1b8f3cffad 100644
--- a/examples/widgets/widgets/wiggly/wigglywidget.cpp
+++ b/examples/widgets/widgets/wiggly/wigglywidget.cpp
@@ -77,7 +77,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
};
QFontMetrics metrics(font());
- int x = (width() - metrics.width(text)) / 2;
+ int x = (width() - metrics.horizontalAdvance(text)) / 2;
int y = (height() + metrics.ascent() - metrics.descent()) / 2;
QColor color;
//! [2]
@@ -91,7 +91,7 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */)
painter.setPen(color);
painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400),
QString(text[i]));
- x += metrics.width(text[i]);
+ x += metrics.horizontalAdvance(text[i]);
}
}
//! [4]