From 525a660ea3ea28437c6cca28cae937b71001a4e3 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 22 May 2015 11:55:50 +0200 Subject: [PATCH] Clarify QPainter::drawText() documentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ƶ Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/doc/images/qpainter-text-bounds.png | Bin 0 -> 1501 bytes .../code/src_gui_painting_qpainter.cpp | 20 ++++++++ src/gui/painting/qpainter.cpp | 43 +++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/gui/doc/images/qpainter-text-bounds.png 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 0000000000000000000000000000000000000000..f92b8502f4e3282107e86d4ed4d4ca3ee00998dc GIT binary patch literal 1501 zcmV<31tR*1P)2&;hhOeje z`9dqoCnp13PmCNbPo{>@^F(R~ee!zE$s9^@q0{Mzo?$GU3<7{BQ%mqXRS#$d^f8i_->X%2)S4pvXd{SYxz*)vZOWmlc^E- zGOIF_tX2ScZB|S0-K>h>yIBq)gx6*@2T!I((CKvI_e?djzrRoXem|L*m>}VB_^KXS zQc^%-aESz2RLdY_`vCLaoS>2a-X)hxAFY>^Bd!q%Wu7UlX-A(0K46uaw0EVYin!TVv~EH_V)H* zv)OKqSqZ95W+IWmn>TMnx~i%w3=a=uWn~4?XcWiC#|VeR7#tjg$z&4s9~&EE9-CYZ z0JOHYinL{AW$=2v+D&F45TN?&^?GHB9r<2`7@>WdcA+X34bA($#crd$-(OCs-&@`qRQIr)YKGZ zcXxNERJUwuYNG6)KYucbO9|7{)0ExP(n2aLE2(Rmtj*5O&Qi9^w)|mH)c+^>xaA`0$~kvG?}&6zN$Ii9{&d;cze?LzPda zAP7wT9UUDp^(TkqIhjl*rv7g{H>-v-Ksh-%Bp#158TWGRL?Xc?Ho2PQImKczlAX=A zG_J~%1_cELO#NkLWij<92cywQ*(WC_%*RmWZnmhXh_VGiAh>vqlGS3dScYcuAH~JR zl)b&ZE$XAm-E2ig1!XTTE@mbWhFGmu%3fGlVCo-gJ!#-{Iw^Z{axz1au;b;+my{h0 z2GcSQRYf2wsLf7HOi+EzW;0GtPnpGXS8TCZjJf9f_wS+#(AwIX$fv?Ns4toEcpMgs zh3fzI?OSHCB$Jz)OO2I$lUZpT4hN-q_3G8%t<5qUC`G>>k4L2G>FG)71i{hKk)(bP z9z3AN85kHyi)M6mR5Yiywl-#~jw+u_060HC$BP#)M7q+_QuO!tV|scT8yg#lMx%(u zVmLTB!1D4k0)YT}dwXHC*(BXy0C2fn)EIib9$j5sn3bBz@#Dvjl>MKdpTp<#p`)V%j~_oqVPPRY zefq>)bDf=?9SjW(p{c0}Hk&Qwn6JZs(?CP0vNrp#qRHAUCv~9K+AK#N)OJseKc4$9 zT~`ACg)WVu%992hdGPN{jlh>#jiJBkOPPQEe}4W2RCKnAN1+9t00000NkvXXu0mjf D10mxu literal 0 HcmV?d00001 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