summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-05-22 11:55:50 +0200
committerMitch Curtis <mitch.curtis@digia.com>2015-06-03 13:41:37 +0000
commit525a660ea3ea28437c6cca28cae937b71001a4e3 (patch)
tree70e1623414021d9673540e20ae6a8976c4f9d339
parent8f760808e0fe0fe6dd89d561f118b19ed8085e7a (diff)
Clarify QPainter::drawText() documentation.
The difference between rectangle and boundingRect was not quite clear. This patch adds a snippet with a corresponding image, in order to illustrate the difference. Change-Id: Icb1fe737788cc93f1c5baa16bc0e04b8ec728f3a Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
-rw-r--r--src/gui/doc/images/qpainter-text-bounds.pngbin0 -> 1501 bytes
-rw-r--r--src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp20
-rw-r--r--src/gui/painting/qpainter.cpp43
3 files changed, 56 insertions, 7 deletions
diff --git a/src/gui/doc/images/qpainter-text-bounds.png b/src/gui/doc/images/qpainter-text-bounds.png
new file mode 100644
index 0000000000..f92b8502f4
--- /dev/null
+++ b/src/gui/doc/images/qpainter-text-bounds.png
Binary files differ
diff --git a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp
index 1367ab2f8c..6d0308b1e9 100644
--- a/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp
+++ b/src/gui/doc/snippets/code/src_gui_painting_qpainter.cpp
@@ -257,3 +257,23 @@ glDisable(GL_SCISSOR_TEST);
painter.endNativePainting();
//! [21]
+
+//! [drawText]
+QPainter painter(this);
+QFont font = painter.font();
+font.setPixelSize(48);
+painter.setFont(font);
+
+const QRect rectangle = QRect(0, 0, 100, 50);
+QRect boundingRect;
+painter.drawText(rectangle, 0, tr("Hello"), &boundingRect);
+
+QPen pen = painter.pen();
+pen.setStyle(Qt::DotLine);
+painter.setPen(pen);
+painter.drawRect(boundingRect.adjusted(0, 0, -pen.width(), -pen.width()));
+
+pen.setStyle(Qt::DashLine);
+painter.setPen(pen);
+painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width()));
+//! [drawText]
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 973c9da96c..213ecc5f8e 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -5966,8 +5966,17 @@ void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br
\endtable
The \a boundingRect (if not null) is set to the what the bounding rectangle
- should be in order to enclose the whole text. The \a flags argument is a bitwise
- OR of the following flags:
+ should be in order to enclose the whole text. For example, in the following
+ image, the dotted line represents \a boundingRect as calculated by the
+ function, and the dashed line represents \a rectangle:
+
+ \table 100%
+ \row
+ \li \inlineimage qpainter-text-bounds.png
+ \li \snippet code/src_gui_painting_qpainter.cpp drawText
+ \endtable
+
+ The \a flags argument is a bitwise OR of the following flags:
\list
\li Qt::AlignLeft
@@ -6016,8 +6025,18 @@ void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *
\overload
Draws the given \a text within the provided \a rectangle according
- to the specified \a flags. The \a boundingRect (if not null) is set to
- the what the bounding rectangle should be in order to enclose the whole text.
+ to the specified \a flags.
+
+ The \a boundingRect (if not null) is set to the what the bounding rectangle
+ should be in order to enclose the whole text. For example, in the following
+ image, the dotted line represents \a boundingRect as calculated by the
+ function, and the dashed line represents \a rectangle:
+
+ \table 100%
+ \row
+ \li \inlineimage qpainter-text-bounds.png
+ \li \snippet code/src_gui_painting_qpainter.cpp drawText
+ \endtable
By default, QPainter draws text anti-aliased.
@@ -6050,9 +6069,19 @@ void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *
Draws the given \a text within the rectangle with origin (\a{x},
\a{y}), \a width and \a height.
- The \a boundingRect (if not null) is set to the actual bounding
- rectangle of the output. The \a flags argument is a bitwise OR of
- the following flags:
+ The \a boundingRect (if not null) is set to the what the bounding rectangle
+ should be in order to enclose the whole text. For example, in the following
+ image, the dotted line represents \a boundingRect as calculated by the
+ function, and the dashed line represents the rectangle defined by
+ \a x, \a y, \a width and \a height:
+
+ \table 100%
+ \row
+ \li \inlineimage qpainter-text-bounds.png
+ \li \snippet code/src_gui_painting_qpainter.cpp drawText
+ \endtable
+
+ The \a flags argument is a bitwise OR of the following flags:
\list
\li Qt::AlignLeft