1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
50 #include "qpaintdevice.h"
51 #include "qpaintengine.h"
53 #include "qpainter_p.h"
54 #include "qpainterpath.h"
56 #include "qpixmapcache.h"
58 #include "qtextlayout.h"
60 #include "qvarlengtharray.h"
61 #include "qstatictext.h"
62 #include "qglyphrun.h"
64 #include <private/qfontengine_p.h>
65 #include <private/qpaintengine_p.h>
66 #include <private/qemulationpaintengine_p.h>
67 #include <private/qpainterpath_p.h>
68 #include <private/qtextengine_p.h>
69 #include <private/qpaintengine_raster_p.h>
70 #include <private/qmath_p.h>
71 #include <private/qstatictext_p.h>
72 #include <private/qglyphrun_p.h>
73 #include <private/qhexstring_p.h>
74 #include <private/qguiapplication_p.h>
75 #include <private/qrawfont_p.h>
79 #define QGradient_StretchToDevice 0x10000000
80 #define QPaintEngine_OpaqueBackground 0x40000000
82 // #define QT_DEBUG_DRAW
84 bool qt_show_painter_debug_output = true;
87 extern QPixmap qt_pixmapForBrush(int style, bool invert);
89 void qt_format_text(const QFont &font,
90 const QRectF &_r, int tf, const QTextOption *option, const QString& str, QRectF *brect,
91 int tabstops, int* tabarray, int tabarraylen,
93 static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QFontEngine *fe,
94 QTextCharFormat::UnderlineStyle underlineStyle,
95 QTextItem::RenderFlags flags, qreal width,
96 const QTextCharFormat &charFormat);
97 // Helper function to calculate left most position, width and flags for decoration drawing
98 Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray,
99 const QFixedPoint *positions, int glyphCount,
100 QFontEngine *fontEngine, const QFont &font,
101 const QTextCharFormat &charFormat);
103 static inline QGradient::CoordinateMode coordinateMode(const QBrush &brush)
105 switch (brush.style()) {
106 case Qt::LinearGradientPattern:
107 case Qt::RadialGradientPattern:
108 case Qt::ConicalGradientPattern:
109 return brush.gradient()->coordinateMode();
113 return QGradient::LogicalMode;
116 /* Returns true if the gradient requires stretch to device...*/
117 static inline bool check_gradient(const QBrush &brush)
119 return coordinateMode(brush) == QGradient::StretchToDeviceMode;
122 extern bool qHasPixmapTexture(const QBrush &);
124 static inline bool is_brush_transparent(const QBrush &brush) {
125 Qt::BrushStyle s = brush.style();
126 bool brushBitmap = qHasPixmapTexture(brush)
127 ? brush.texture().isQBitmap()
128 : (brush.textureImage().depth() == 1);
129 return ((s >= Qt::Dense1Pattern && s <= Qt::DiagCrossPattern)
130 || (s == Qt::TexturePattern && brushBitmap));
133 static inline bool is_pen_transparent(const QPen &pen) {
134 return pen.style() > Qt::SolidLine || is_brush_transparent(pen.brush());
137 /* Discards the emulation flags that are not relevant for line drawing
138 and returns the result
140 static inline uint line_emulation(uint emulation)
142 return emulation & (QPaintEngine::PrimitiveTransform
143 | QPaintEngine::AlphaBlend
144 | QPaintEngine::Antialiasing
145 | QPaintEngine::BrushStroke
146 | QPaintEngine::ConstantOpacity
147 | QGradient_StretchToDevice
148 | QPaintEngine::ObjectBoundingModeGradients
149 | QPaintEngine_OpaqueBackground);
153 static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition = false)
156 case QInternal::Image:
157 case QInternal::Printer:
158 case QInternal::Picture:
159 // can be drawn onto these devices safely from any thread
166 if (QApplication::testAttribute(Qt::AA_X11InitThreads))
169 if (!extraCondition && QThread::currentThread() != qApp->thread()) {
170 qWarning("QPainter: It is not safe to use %s outside the GUI thread", what);
179 void QPainterPrivate::checkEmulation()
182 if (extended->flags() & QPaintEngineEx::DoNotEmulate)
185 bool doEmulation = false;
186 if (state->bgMode == Qt::OpaqueMode)
189 const QGradient *bg = state->brush.gradient();
190 if (bg && bg->coordinateMode() > QGradient::LogicalMode)
193 const QGradient *pg = qpen_brush(state->pen).gradient();
194 if (pg && pg->coordinateMode() > QGradient::LogicalMode)
198 if (extended != emulationEngine) {
199 if (!emulationEngine)
200 emulationEngine = new QEmulationPaintEngine(extended);
201 extended = emulationEngine;
202 extended->setState(state);
204 } else if (emulationEngine == extended) {
205 extended = emulationEngine->real_engine;
210 QPainterPrivate::~QPainterPrivate()
212 delete emulationEngine;
213 for (int i=0; i<states.size(); ++i)
221 QTransform QPainterPrivate::viewTransform() const
224 qreal scaleW = qreal(state->vw)/qreal(state->ww);
225 qreal scaleH = qreal(state->vh)/qreal(state->wh);
226 return QTransform(scaleW, 0, 0, scaleH,
227 state->vx - state->wx*scaleW, state->vy - state->wy*scaleH);
235 Returns true if using a shared painter; otherwise false.
237 bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev)
242 QPainter *sp = pdev->sharedPainter();
246 // Save the current state of the shared painter and assign
247 // the current d_ptr to the shared painter's d_ptr.
249 if (!sp->d_ptr->d_ptrs) {
250 // Allocate space for 4 d-pointers (enough for up to 4 sub-sequent
251 // redirections within the same paintEvent(), which should be enough
252 // in 99% of all cases). E.g: A renders B which renders C which renders D.
253 sp->d_ptr->d_ptrs_size = 4;
254 sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *));
255 Q_CHECK_PTR(sp->d_ptr->d_ptrs);
256 } else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) {
257 // However, to support corner cases we grow the array dynamically if needed.
258 sp->d_ptr->d_ptrs_size <<= 1;
259 const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *);
260 sp->d_ptr->d_ptrs = q_check_ptr((QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize));
262 sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data();
264 q->d_ptr.reset(sp->d_ptr.data());
266 Q_ASSERT(q->d_ptr->state);
268 // Now initialize the painter with correct widget properties.
271 pdev->redirected(&offset);
272 offset += q->d_ptr->engine->coordinateOffset();
274 // Update system rect.
275 q->d_ptr->state->ww = q->d_ptr->state->vw = pdev->width();
276 q->d_ptr->state->wh = q->d_ptr->state->vh = pdev->height();
279 if (q->d_ptr->state->WxF) {
280 q->d_ptr->state->redirectionMatrix = q->d_ptr->state->matrix;
281 q->d_ptr->state->redirectionMatrix.translate(-offset.x(), -offset.y());
282 q->d_ptr->state->worldMatrix = QTransform();
283 q->d_ptr->state->WxF = false;
285 q->d_ptr->state->redirectionMatrix = QTransform::fromTranslate(-offset.x(), -offset.y());
287 q->d_ptr->updateMatrix();
289 QPaintEnginePrivate *enginePrivate = q->d_ptr->engine->d_func();
290 if (enginePrivate->currentClipDevice == pdev) {
291 enginePrivate->systemStateChanged();
295 // Update system transform and clip.
296 enginePrivate->currentClipDevice = pdev;
297 enginePrivate->setSystemTransform(q->d_ptr->state->matrix);
301 void QPainterPrivate::detachPainterPrivate(QPainter *q)
303 Q_ASSERT(refcount > 1);
306 QPainterPrivate *original = d_ptrs[--refcount - 1];
308 inDestructor = false;
310 original->inDestructor = true;
311 } else if (!original) {
312 original = new QPainterPrivate(q);
315 d_ptrs[refcount - 1] = 0;
318 q->d_ptr.reset(original);
320 if (emulationEngine) {
321 extended = emulationEngine->real_engine;
322 delete emulationEngine;
328 void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperation op)
331 if (qt_show_painter_debug_output) {
332 printf("QPainter::drawHelper\n");
336 if (originalPath.isEmpty())
339 QPaintEngine::PaintEngineFeatures gradientStretch =
340 QPaintEngine::PaintEngineFeatures(QGradient_StretchToDevice
341 | QPaintEngine::ObjectBoundingModeGradients);
343 const bool mustEmulateObjectBoundingModeGradients = extended
344 || ((state->emulationSpecifier & QPaintEngine::ObjectBoundingModeGradients)
345 && !engine->hasFeature(QPaintEngine::PatternTransform));
347 if (!(state->emulationSpecifier & ~gradientStretch)
348 && !mustEmulateObjectBoundingModeGradients) {
349 drawStretchedGradient(originalPath, op);
351 } else if (state->emulationSpecifier & QPaintEngine_OpaqueBackground) {
352 drawOpaqueBackground(originalPath, op);
358 qreal strokeOffsetX = 0, strokeOffsetY = 0;
360 QPainterPath path = originalPath * state->matrix;
361 QRectF pathBounds = path.boundingRect();
363 bool doStroke = (op & StrokeDraw) && (state->pen.style() != Qt::NoPen);
365 qreal penWidth = state->pen.widthF();
370 // In case of complex xform
371 if (state->matrix.type() > QTransform::TxScale) {
372 QPainterPathStroker stroker;
373 stroker.setWidth(penWidth);
374 stroker.setJoinStyle(state->pen.joinStyle());
375 stroker.setCapStyle(state->pen.capStyle());
376 QPainterPath stroke = stroker.createStroke(originalPath);
377 strokeBounds = (stroke * state->matrix).boundingRect();
379 strokeOffsetX = qAbs(penWidth * state->matrix.m11() / 2.0);
380 strokeOffsetY = qAbs(penWidth * state->matrix.m22() / 2.0);
386 if (!strokeBounds.isEmpty()) {
387 absPathRect = strokeBounds.intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect();
389 absPathRect = pathBounds.adjusted(-strokeOffsetX, -strokeOffsetY, strokeOffsetX, strokeOffsetY)
390 .intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect();
393 if (q->hasClipping()) {
394 bool hasPerspectiveTransform = false;
395 for (int i = 0; i < state->clipInfo.size(); ++i) {
396 const QPainterClipInfo &info = state->clipInfo.at(i);
397 if (info.matrix.type() == QTransform::TxProject) {
398 hasPerspectiveTransform = true;
402 // avoid mapping QRegions with perspective transforms
403 if (!hasPerspectiveTransform) {
404 // The trick with txinv and invMatrix is done in order to
405 // avoid transforming the clip to logical coordinates, and
406 // then back to device coordinates. This is a problem with
407 // QRegion/QRect based clips, since they use integer
408 // coordinates and converting to/from logical coordinates will
410 bool old_txinv = txinv;
411 QTransform old_invMatrix = invMatrix;
413 invMatrix = QTransform();
414 QPainterPath clipPath = q->clipPath();
415 QRectF r = clipPath.boundingRect().intersected(absPathRect);
416 absPathRect = r.toAlignedRect();
418 invMatrix = old_invMatrix;
422 // qDebug("\nQPainterPrivate::draw_helper(), x=%d, y=%d, w=%d, h=%d",
423 // devMinX, devMinY, device->width(), device->height());
424 // qDebug() << " - matrix" << state->matrix;
425 // qDebug() << " - originalPath.bounds" << originalPath.boundingRect();
426 // qDebug() << " - path.bounds" << path.boundingRect();
428 if (absPathRect.width() <= 0 || absPathRect.height() <= 0)
431 QImage image(absPathRect.width(), absPathRect.height(), QImage::Format_ARGB32_Premultiplied);
436 p.d_ptr->helper_device = helper_device;
438 p.setOpacity(state->opacity);
439 p.translate(-absPathRect.x(), -absPathRect.y());
440 p.setTransform(state->matrix, true);
441 p.setPen(doStroke ? state->pen : QPen(Qt::NoPen));
442 p.setBrush((op & FillDraw) ? state->brush : QBrush(Qt::NoBrush));
443 p.setBackground(state->bgBrush);
444 p.setBackgroundMode(state->bgMode);
445 p.setBrushOrigin(state->brushOrigin);
447 p.setRenderHint(QPainter::Antialiasing, state->renderHints & QPainter::Antialiasing);
448 p.setRenderHint(QPainter::SmoothPixmapTransform,
449 state->renderHints & QPainter::SmoothPixmapTransform);
451 p.drawPath(originalPath);
454 static bool do_fallback_overlay = qgetenv("QT_PAINT_FALLBACK_OVERLAY").size() > 0;
455 if (do_fallback_overlay) {
456 QImage block(8, 8, QImage::Format_ARGB32_Premultiplied);
458 pt.fillRect(0, 0, 8, 8, QColor(196, 0, 196));
459 pt.drawLine(0, 0, 8, 8);
462 p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
464 p.fillRect(0, 0, image.width(), image.height(), QBrush(block));
471 state->matrix = QTransform();
473 extended->transformChanged();
475 state->dirtyFlags |= QPaintEngine::DirtyTransform;
478 engine->drawImage(absPathRect,
480 QRectF(0, 0, absPathRect.width(), absPathRect.height()),
481 Qt::OrderedDither | Qt::OrderedAlphaDither);
485 void QPainterPrivate::drawOpaqueBackground(const QPainterPath &path, DrawOperation op)
489 q->setBackgroundMode(Qt::TransparentMode);
491 if (op & FillDraw && state->brush.style() != Qt::NoBrush) {
492 q->fillPath(path, state->bgBrush.color());
493 q->fillPath(path, state->brush);
496 if (op & StrokeDraw && state->pen.style() != Qt::NoPen) {
497 q->strokePath(path, QPen(state->bgBrush.color(), state->pen.width()));
498 q->strokePath(path, state->pen);
501 q->setBackgroundMode(Qt::OpaqueMode);
504 static inline QBrush stretchGradientToUserSpace(const QBrush &brush, const QRectF &boundingRect)
506 Q_ASSERT(brush.style() >= Qt::LinearGradientPattern
507 && brush.style() <= Qt::ConicalGradientPattern);
509 QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(),
510 boundingRect.x(), boundingRect.y());
512 QGradient g = *brush.gradient();
513 g.setCoordinateMode(QGradient::LogicalMode);
516 b.setTransform(gradientToUser * b.transform());
520 void QPainterPrivate::drawStretchedGradient(const QPainterPath &path, DrawOperation op)
524 const qreal sw = helper_device->width();
525 const qreal sh = helper_device->height();
527 bool changedPen = false;
528 bool changedBrush = false;
529 bool needsFill = false;
531 const QPen pen = state->pen;
532 const QBrush brush = state->brush;
534 const QGradient::CoordinateMode penMode = coordinateMode(pen.brush());
535 const QGradient::CoordinateMode brushMode = coordinateMode(brush);
539 // Draw the xformed fill if the brush is a stretch gradient.
540 if ((op & FillDraw) && brush.style() != Qt::NoBrush) {
541 if (brushMode == QGradient::StretchToDeviceMode) {
542 q->setPen(Qt::NoPen);
543 changedPen = pen.style() != Qt::NoPen;
547 const qreal isw = 1.0 / sw;
548 const qreal ish = 1.0 / sh;
549 QTransform inv(isw, 0, 0, ish, 0, 0);
550 engine->drawPath(path * inv);
555 if (brushMode == QGradient::ObjectBoundingMode) {
556 Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform));
557 boundingRect = path.boundingRect();
558 q->setBrush(stretchGradientToUserSpace(brush, boundingRect));
564 if ((op & StrokeDraw) && pen.style() != Qt::NoPen) {
565 // Draw the xformed outline if the pen is a stretch gradient.
566 if (penMode == QGradient::StretchToDeviceMode) {
567 q->setPen(Qt::NoPen);
572 engine->drawPath(path);
576 q->setBrush(pen.brush());
580 QPainterPathStroker stroker;
581 stroker.setDashPattern(pen.style());
582 stroker.setWidth(pen.widthF());
583 stroker.setJoinStyle(pen.joinStyle());
584 stroker.setCapStyle(pen.capStyle());
585 stroker.setMiterLimit(pen.miterLimit());
586 QPainterPath stroke = stroker.createStroke(path);
588 const qreal isw = 1.0 / sw;
589 const qreal ish = 1.0 / sh;
590 QTransform inv(isw, 0, 0, ish, 0, 0);
591 engine->drawPath(stroke * inv);
594 if (!needsFill && brush.style() != Qt::NoBrush) {
595 q->setBrush(Qt::NoBrush);
599 if (penMode == QGradient::ObjectBoundingMode) {
600 Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform));
602 // avoid computing the bounding rect twice
603 if (!needsFill || brushMode != QGradient::ObjectBoundingMode)
604 boundingRect = path.boundingRect();
607 p.setBrush(stretchGradientToUserSpace(pen.brush(), boundingRect));
610 } else if (changedPen) {
616 engine->drawPath(path);
618 } else if (needsFill) {
619 if (pen.style() != Qt::NoPen) {
620 q->setPen(Qt::NoPen);
625 engine->drawPath(path);
635 void QPainterPrivate::updateMatrix()
637 state->matrix = state->WxF ? state->worldMatrix : QTransform();
639 state->matrix *= viewTransform();
641 txinv = false; // no inverted matrix
642 state->matrix *= state->redirectionMatrix;
644 extended->transformChanged();
646 state->dirtyFlags |= QPaintEngine::DirtyTransform;
648 // printf("VxF=%d, WxF=%d\n", state->VxF, state->WxF);
649 // qDebug() << " --- using matrix" << state->matrix << redirection_offset;
653 void QPainterPrivate::updateInvMatrix()
655 Q_ASSERT(txinv == false);
656 txinv = true; // creating inverted matrix
657 invMatrix = state->matrix.inverted();
660 extern bool qt_isExtendedRadialGradient(const QBrush &brush);
662 void QPainterPrivate::updateEmulationSpecifier(QPainterState *s)
665 bool linearGradient = false;
666 bool radialGradient = false;
667 bool extendedRadialGradient = false;
668 bool conicalGradient = false;
669 bool patternBrush = false;
671 bool complexXform = false;
675 // Pen and brush properties (we have to check both if one changes because the
676 // one that's unchanged can still be in a state which requires emulation)
677 if (s->state() & (QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush | QPaintEngine::DirtyHints)) {
678 // Check Brush stroke emulation
679 if (!s->pen.isSolid() && !engine->hasFeature(QPaintEngine::BrushStroke))
680 s->emulationSpecifier |= QPaintEngine::BrushStroke;
682 s->emulationSpecifier &= ~QPaintEngine::BrushStroke;
686 QBrush penBrush = (qpen_style(s->pen) == Qt::NoPen) ? QBrush(Qt::NoBrush) : qpen_brush(s->pen);
687 Qt::BrushStyle brushStyle = qbrush_style(s->brush);
688 Qt::BrushStyle penBrushStyle = qbrush_style(penBrush);
689 alpha = (penBrushStyle != Qt::NoBrush
690 && (penBrushStyle < Qt::LinearGradientPattern && penBrush.color().alpha() != 255)
691 && !penBrush.isOpaque())
692 || (brushStyle != Qt::NoBrush
693 && (brushStyle < Qt::LinearGradientPattern && s->brush.color().alpha() != 255)
694 && !s->brush.isOpaque());
695 linearGradient = ((penBrushStyle == Qt::LinearGradientPattern) ||
696 (brushStyle == Qt::LinearGradientPattern));
697 radialGradient = ((penBrushStyle == Qt::RadialGradientPattern) ||
698 (brushStyle == Qt::RadialGradientPattern));
699 extendedRadialGradient = radialGradient && (qt_isExtendedRadialGradient(penBrush) || qt_isExtendedRadialGradient(s->brush));
700 conicalGradient = ((penBrushStyle == Qt::ConicalGradientPattern) ||
701 (brushStyle == Qt::ConicalGradientPattern));
702 patternBrush = (((penBrushStyle > Qt::SolidPattern
703 && penBrushStyle < Qt::LinearGradientPattern)
704 || penBrushStyle == Qt::TexturePattern) ||
705 ((brushStyle > Qt::SolidPattern
706 && brushStyle < Qt::LinearGradientPattern)
707 || brushStyle == Qt::TexturePattern));
709 bool penTextureAlpha = false;
710 if (penBrush.style() == Qt::TexturePattern)
711 penTextureAlpha = qHasPixmapTexture(penBrush)
712 ? (penBrush.texture().depth() > 1) && penBrush.texture().hasAlpha()
713 : penBrush.textureImage().hasAlphaChannel();
714 bool brushTextureAlpha = false;
715 if (s->brush.style() == Qt::TexturePattern) {
716 brushTextureAlpha = qHasPixmapTexture(s->brush)
717 ? (s->brush.texture().depth() > 1) && s->brush.texture().hasAlpha()
718 : s->brush.textureImage().hasAlphaChannel();
720 if (((penBrush.style() == Qt::TexturePattern && penTextureAlpha)
721 || (s->brush.style() == Qt::TexturePattern && brushTextureAlpha))
722 && !engine->hasFeature(QPaintEngine::MaskedBrush))
723 s->emulationSpecifier |= QPaintEngine::MaskedBrush;
725 s->emulationSpecifier &= ~QPaintEngine::MaskedBrush;
728 if (s->state() & (QPaintEngine::DirtyHints
729 | QPaintEngine::DirtyOpacity
730 | QPaintEngine::DirtyBackgroundMode)) {
738 qDebug("QPainterPrivate::updateEmulationSpecifier, state=%p\n"
740 " - linearGradient: %d\n"
741 " - radialGradient: %d\n"
742 " - conicalGradient: %d\n"
743 " - patternBrush: %d\n"
752 uint(s->renderHints),
757 if (s->state() & QPaintEngine::DirtyTransform) {
758 xform = !s->matrix.isIdentity();
759 complexXform = !s->matrix.isAffine();
760 } else if (s->matrix.type() >= QTransform::TxTranslate) {
762 complexXform = !s->matrix.isAffine();
765 const bool brushXform = (!s->brush.transform().type() == QTransform::TxNone);
766 const bool penXform = (!s->pen.brush().transform().type() == QTransform::TxNone);
768 const bool patternXform = patternBrush && (xform || brushXform || penXform);
770 // Check alphablending
771 if (alpha && !engine->hasFeature(QPaintEngine::AlphaBlend))
772 s->emulationSpecifier |= QPaintEngine::AlphaBlend;
774 s->emulationSpecifier &= ~QPaintEngine::AlphaBlend;
776 // Linear gradient emulation
777 if (linearGradient && !engine->hasFeature(QPaintEngine::LinearGradientFill))
778 s->emulationSpecifier |= QPaintEngine::LinearGradientFill;
780 s->emulationSpecifier &= ~QPaintEngine::LinearGradientFill;
782 // Radial gradient emulation
783 if (extendedRadialGradient || (radialGradient && !engine->hasFeature(QPaintEngine::RadialGradientFill)))
784 s->emulationSpecifier |= QPaintEngine::RadialGradientFill;
786 s->emulationSpecifier &= ~QPaintEngine::RadialGradientFill;
788 // Conical gradient emulation
789 if (conicalGradient && !engine->hasFeature(QPaintEngine::ConicalGradientFill))
790 s->emulationSpecifier |= QPaintEngine::ConicalGradientFill;
792 s->emulationSpecifier &= ~QPaintEngine::ConicalGradientFill;
795 if (patternBrush && !engine->hasFeature(QPaintEngine::PatternBrush))
796 s->emulationSpecifier |= QPaintEngine::PatternBrush;
798 s->emulationSpecifier &= ~QPaintEngine::PatternBrush;
801 if (patternXform && !engine->hasFeature(QPaintEngine::PatternTransform))
802 s->emulationSpecifier |= QPaintEngine::PatternTransform;
804 s->emulationSpecifier &= ~QPaintEngine::PatternTransform;
807 if (xform && !engine->hasFeature(QPaintEngine::PrimitiveTransform))
808 s->emulationSpecifier |= QPaintEngine::PrimitiveTransform;
810 s->emulationSpecifier &= ~QPaintEngine::PrimitiveTransform;
812 // Perspective XForms
813 if (complexXform && !engine->hasFeature(QPaintEngine::PerspectiveTransform))
814 s->emulationSpecifier |= QPaintEngine::PerspectiveTransform;
816 s->emulationSpecifier &= ~QPaintEngine::PerspectiveTransform;
819 if (state->opacity != 1 && !engine->hasFeature(QPaintEngine::ConstantOpacity))
820 s->emulationSpecifier |= QPaintEngine::ConstantOpacity;
822 s->emulationSpecifier &= ~QPaintEngine::ConstantOpacity;
824 bool gradientStretch = false;
825 bool objectBoundingMode = false;
826 if (linearGradient || conicalGradient || radialGradient) {
827 QGradient::CoordinateMode brushMode = coordinateMode(s->brush);
828 QGradient::CoordinateMode penMode = coordinateMode(s->pen.brush());
830 gradientStretch |= (brushMode == QGradient::StretchToDeviceMode);
831 gradientStretch |= (penMode == QGradient::StretchToDeviceMode);
833 objectBoundingMode |= (brushMode == QGradient::ObjectBoundingMode);
834 objectBoundingMode |= (penMode == QGradient::ObjectBoundingMode);
837 s->emulationSpecifier |= QGradient_StretchToDevice;
839 s->emulationSpecifier &= ~QGradient_StretchToDevice;
841 if (objectBoundingMode && !engine->hasFeature(QPaintEngine::ObjectBoundingModeGradients))
842 s->emulationSpecifier |= QPaintEngine::ObjectBoundingModeGradients;
844 s->emulationSpecifier &= ~QPaintEngine::ObjectBoundingModeGradients;
846 // Opaque backgrounds...
847 if (s->bgMode == Qt::OpaqueMode &&
848 (is_pen_transparent(s->pen) || is_brush_transparent(s->brush)))
849 s->emulationSpecifier |= QPaintEngine_OpaqueBackground;
851 s->emulationSpecifier &= ~QPaintEngine_OpaqueBackground;
854 //won't be correct either way because the device can already have
855 // something rendered to it in which case subsequent emulation
856 // on a fully transparent qimage and then blitting the results
857 // won't produce correct results
859 if (state->composition_mode > QPainter::CompositionMode_Xor &&
860 !engine->hasFeature(QPaintEngine::BlendModes))
861 s->emulationSpecifier |= QPaintEngine::BlendModes;
863 s->emulationSpecifier &= ~QPaintEngine::BlendModes;
867 void QPainterPrivate::updateStateImpl(QPainterState *newState)
869 // ### we might have to call QPainter::begin() here...
870 if (!engine->state) {
871 engine->state = newState;
872 engine->setDirty(QPaintEngine::AllDirty);
875 if (engine->state->painter() != newState->painter)
876 // ### this could break with clip regions vs paths.
877 engine->setDirty(QPaintEngine::AllDirty);
879 // Upon restore, revert all changes since last save
880 else if (engine->state != newState)
881 newState->dirtyFlags |= QPaintEngine::DirtyFlags(static_cast<QPainterState *>(engine->state)->changeFlags);
883 // We need to store all changes made so that restore can deal with them
885 newState->changeFlags |= newState->dirtyFlags;
887 updateEmulationSpecifier(newState);
889 // Unset potential dirty background mode
890 newState->dirtyFlags &= ~(QPaintEngine::DirtyBackgroundMode
891 | QPaintEngine::DirtyBackground);
893 engine->state = newState;
894 engine->updateState(*newState);
895 engine->clearDirty(QPaintEngine::AllDirty);
899 void QPainterPrivate::updateState(QPainterState *newState)
903 engine->state = newState;
905 } else if (newState->state() || engine->state!=newState) {
906 bool setNonCosmeticPen = (newState->renderHints & QPainter::NonCosmeticDefaultPen)
907 && newState->pen.widthF() == 0;
908 if (setNonCosmeticPen) {
909 // Override the default pen's cosmetic state if the
910 // NonCosmeticDefaultPen render hint is used.
911 QPen oldPen = newState->pen;
912 newState->pen.setWidth(1);
913 newState->pen.setCosmetic(false);
914 newState->dirtyFlags |= QPaintEngine::DirtyPen;
916 updateStateImpl(newState);
918 // Restore the state pen back to its default to preserve visible
920 newState->pen = oldPen;
922 updateStateImpl(newState);
930 \brief The QPainter class performs low-level painting on widgets and
937 QPainter provides highly optimized functions to do most of the
938 drawing GUI programs require. It can draw everything from simple
939 lines to complex shapes like pies and chords. It can also draw
940 aligned text and pixmaps. Normally, it draws in a "natural"
941 coordinate system, but it can also do view and world
942 transformation. QPainter can operate on any object that inherits
943 the QPaintDevice class.
945 The common use of QPainter is inside a widget's paint event:
946 Construct and customize (e.g. set the pen or the brush) the
947 painter. Then draw. Remember to destroy the QPainter object after
948 drawing. For example:
950 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 0
952 The core functionality of QPainter is drawing, but the class also
953 provide several functions that allows you to customize QPainter's
954 settings and its rendering quality, and others that enable
955 clipping. In addition you can control how different shapes are
956 merged together by specifying the painter's composition mode.
958 The isActive() function indicates whether the painter is active. A
959 painter is activated by the begin() function and the constructor
960 that takes a QPaintDevice argument. The end() function, and the
961 destructor, deactivates it.
963 Together with the QPaintDevice and QPaintEngine classes, QPainter
964 form the basis for Qt's paint system. QPainter is the class used
965 to perform drawing operations. QPaintDevice represents a device
966 that can be painted on using a QPainter. QPaintEngine provides the
967 interface that the painter uses to draw onto different types of
968 devices. If the painter is active, device() returns the paint
969 device on which the painter paints, and paintEngine() returns the
970 paint engine that the painter is currently operating on. For more
971 information, see the \l {Paint System}.
973 Sometimes it is desirable to make someone else paint on an unusual
974 QPaintDevice. QPainter supports a static function to do this,
977 \warning When the paintdevice is a widget, QPainter can only be
978 used inside a paintEvent() function or in a function called by
979 paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent
980 widget attribute is set. On Mac OS X and Windows, you can only
981 paint in a paintEvent() function regardless of this attribute's
988 There are several settings that you can customize to make QPainter
989 draw according to your preferences:
993 \o font() is the font used for drawing text. If the painter
994 isActive(), you can retrieve information about the currently set
995 font, and its metrics, using the fontInfo() and fontMetrics()
996 functions respectively.
998 \o brush() defines the color or pattern that is used for filling
1001 \o pen() defines the color or stipple that is used for drawing
1002 lines or boundaries.
1004 \o backgroundMode() defines whether there is a background() or
1005 not, i.e it is either Qt::OpaqueMode or Qt::TransparentMode.
1007 \o background() only applies when backgroundMode() is \l
1008 Qt::OpaqueMode and pen() is a stipple. In that case, it
1009 describes the color of the background pixels in the stipple.
1011 \o brushOrigin() defines the origin of the tiled brushes, normally
1012 the origin of widget's background.
1014 \o viewport(), window(), worldTransform() make up the painter's coordinate
1015 transformation system. For more information, see the \l
1016 {Coordinate Transformations} section and the \l {Coordinate
1017 System} documentation.
1019 \o hasClipping() tells whether the painter clips at all. (The paint
1020 device clips, too.) If the painter clips, it clips to clipRegion().
1022 \o layoutDirection() defines the layout direction used by the
1023 painter when drawing text.
1025 \o worldMatrixEnabled() tells whether world transformation is enabled.
1027 \o viewTransformEnabled() tells whether view transformation is
1032 Note that some of these settings mirror settings in some paint
1033 devices, e.g. QWidget::font(). The QPainter::begin() function (or
1034 equivalently the QPainter constructor) copies these attributes
1035 from the paint device.
1037 You can at any time save the QPainter's state by calling the
1038 save() function which saves all the available settings on an
1039 internal stack. The restore() function pops them back.
1043 QPainter provides functions to draw most primitives: drawPoint(),
1044 drawPoints(), drawLine(), drawRect(), drawRoundedRect(),
1045 drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(),
1046 drawPolygon(), drawConvexPolygon() and drawCubicBezier(). The two
1047 convenience functions, drawRects() and drawLines(), draw the given
1048 number of rectangles or lines in the given array of \l
1049 {QRect}{QRects} or \l {QLine}{QLines} using the current pen and
1052 The QPainter class also provides the fillRect() function which
1053 fills the given QRect, with the given QBrush, and the eraseRect()
1054 function that erases the area inside the given rectangle.
1056 All of these functions have both integer and floating point
1061 \o \inlineimage qpainter-basicdrawing.png
1063 \bold {Basic Drawing Example}
1065 The \l {painting/basicdrawing}{Basic Drawing} example shows how to
1066 display basic graphics primitives in a variety of styles using the
1071 If you need to draw a complex shape, especially if you need to do
1072 so repeatedly, consider creating a QPainterPath and drawing it
1078 \bold {Painter Paths example}
1080 The QPainterPath class provides a container for painting
1081 operations, enabling graphical shapes to be constructed and
1084 The \l {painting/painterpaths}{Painter Paths} example shows how
1085 painter paths can be used to build complex shapes for rendering.
1087 \o \inlineimage qpainter-painterpaths.png
1090 QPainter also provides the fillPath() function which fills the
1091 given QPainterPath with the given QBrush, and the strokePath()
1092 function that draws the outline of the given path (i.e. strokes
1095 See also the \l {painting/deform}{Vector Deformation} example which
1096 shows how to use advanced vector techniques to draw text using a
1097 QPainterPath, the \l {painting/gradients}{Gradients} example which shows
1098 the different types of gradients that are available in Qt, and the \l
1099 {painting/pathstroke}{Path Stroking} example which shows Qt's built-in
1100 dash patterns and shows how custom patterns can be used to extend
1101 the range of available patterns.
1105 \o \l {painting/deform}{Vector Deformation}
1106 \o \l {painting/gradients}{Gradients}
1107 \o \l {painting/pathstroke}{Path Stroking}
1109 \o \inlineimage qpainter-vectordeformation.png
1110 \o \inlineimage qpainter-gradients.png
1111 \o \inlineimage qpainter-pathstroking.png
1115 There are functions to draw pixmaps/images, namely drawPixmap(),
1116 drawImage() and drawTiledPixmap(). Both drawPixmap() and drawImage()
1117 produce the same result, except that drawPixmap() is faster
1118 on-screen while drawImage() may be faster on a QPrinter or other
1121 Text drawing is done using drawText(). When you need
1122 fine-grained positioning, boundingRect() tells you where a given
1123 drawText() command will draw.
1125 There is a drawPicture() function that draws the contents of an
1126 entire QPicture. The drawPicture() function is the only function
1127 that disregards all the painter's settings as QPicture has its own
1130 \section1 Rendering Quality
1132 To get the optimal rendering result using QPainter, you should use
1133 the platform independent QImage as paint device; i.e. using QImage
1134 will ensure that the result has an identical pixel representation
1137 The QPainter class also provides a means of controlling the
1138 rendering quality through its RenderHint enum and the support for
1139 floating point precision: All the functions for drawing primitives
1140 has a floating point version. These are often used in combination
1141 with the \l {RenderHint}{QPainter::Antialiasing} render hint.
1145 \o \inlineimage qpainter-concentriccircles.png
1147 \bold {Concentric Circles Example}
1149 The \l {painting/concentriccircles}{Concentric Circles} example
1150 shows the improved rendering quality that can be obtained using
1151 floating point precision and anti-aliasing when drawing custom
1154 The application's main window displays several widgets which are
1155 drawn using the various combinations of precision and
1160 The RenderHint enum specifies flags to QPainter that may or may
1161 not be respected by any given engine. \l
1162 {RenderHint}{QPainter::Antialiasing} indicates that the engine
1163 should antialias edges of primitives if possible, \l
1164 {RenderHint}{QPainter::TextAntialiasing} indicates that the engine
1165 should antialias text if possible, and the \l
1166 {RenderHint}{QPainter::SmoothPixmapTransform} indicates that the
1167 engine should use a smooth pixmap transformation algorithm.
1168 \l {RenderHint}{HighQualityAntialiasing} is an OpenGL-specific rendering hint
1169 indicating that the engine should use fragment programs and offscreen
1170 rendering for antialiasing.
1172 The renderHints() function returns a flag that specifies the
1173 rendering hints that are set for this painter. Use the
1174 setRenderHint() function to set or clear the currently set
1177 \section1 Coordinate Transformations
1179 Normally, the QPainter operates on the device's own coordinate
1180 system (usually pixels), but QPainter has good support for
1181 coordinate transformations.
1185 \o nop \o rotate() \o scale() \o translate()
1187 \o \inlineimage qpainter-clock.png
1188 \o \inlineimage qpainter-rotation.png
1189 \o \inlineimage qpainter-scale.png
1190 \o \inlineimage qpainter-translation.png
1193 The most commonly used transformations are scaling, rotation,
1194 translation and shearing. Use the scale() function to scale the
1195 coordinate system by a given offset, the rotate() function to
1196 rotate it clockwise and translate() to translate it (i.e. adding a
1197 given offset to the points). You can also twist the coordinate
1198 system around the origin using the shear() function. See the \l
1199 {painting/affine}{Affine Transformations} example for a visualization of
1200 a sheared coordinate system.
1202 See also the \l {painting/transformations}{Transformations}
1203 example which shows how transformations influence the way that
1204 QPainter renders graphics primitives. In particular it shows how
1205 the order of transformations affects the result.
1210 \bold {Affine Transformations Example}
1212 The \l {painting/affine}{Affine Transformations} example shows Qt's
1213 ability to perform affine transformations on painting
1214 operations. The demo also allows the user to experiment with the
1215 transformation operations and see the results immediately.
1217 \o \inlineimage qpainter-affinetransformations.png
1220 All the tranformation operations operate on the transformation
1221 worldTransform(). A matrix transforms a point in the plane to another
1222 point. For more information about the transformation matrix, see
1223 the \l {Coordinate System} and QTransform documentation.
1225 The setWorldTransform() function can replace or add to the currently
1226 set worldTransform(). The resetTransform() function resets any
1227 transformations that were made using translate(), scale(),
1228 shear(), rotate(), setWorldTransform(), setViewport() and setWindow()
1229 functions. The deviceTransform() returns the matrix that transforms
1230 from logical coordinates to device coordinates of the platform
1231 dependent paint device. The latter function is only needed when
1232 using platform painting commands on the platform dependent handle,
1233 and the platform does not do transformations nativly.
1235 When drawing with QPainter, we specify points using logical
1236 coordinates which then are converted into the physical coordinates
1237 of the paint device. The mapping of the logical coordinates to the
1238 physical coordinates are handled by QPainter's combinedTransform(), a
1239 combination of viewport() and window() and worldTransform(). The
1240 viewport() represents the physical coordinates specifying an
1241 arbitrary rectangle, the window() describes the same rectangle in
1242 logical coordinates, and the worldTransform() is identical with the
1243 transformation matrix.
1245 See also \l {Coordinate System}
1249 QPainter can clip any drawing operation to a rectangle, a region,
1250 or a vector path. The current clip is available using the
1251 functions clipRegion() and clipPath(). Whether paths or regions are
1252 preferred (faster) depends on the underlying paintEngine(). For
1253 example, the QImage paint engine prefers paths while the X11 paint
1254 engine prefers regions. Setting a clip is done in the painters
1255 logical coordinates.
1257 After QPainter's clipping, the paint device may also clip. For
1258 example, most widgets clip away the pixels used by child widgets,
1259 and most printers clip away an area near the edges of the paper.
1260 This additional clipping is not reflected by the return value of
1261 clipRegion() or hasClipping().
1263 \section1 Composition Modes
1264 \target Composition Modes
1266 QPainter provides the CompositionMode enum which defines the
1267 Porter-Duff rules for digital image compositing; it describes a
1268 model for combining the pixels in one image, the source, with the
1269 pixels in another image, the destination.
1271 The two most common forms of composition are \l
1272 {QPainter::CompositionMode}{Source} and \l
1273 {QPainter::CompositionMode}{SourceOver}. \l
1274 {QPainter::CompositionMode}{Source} is used to draw opaque objects
1275 onto a paint device. In this mode, each pixel in the source
1276 replaces the corresponding pixel in the destination. In \l
1277 {QPainter::CompositionMode}{SourceOver} composition mode, the
1278 source object is transparent and is drawn on top of the
1281 Note that composition transformation operates pixelwise. For that
1282 reason, there is a difference between using the graphic primitive
1283 itself and its bounding rectangle: The bounding rect contains
1284 pixels with alpha == 0 (i.e the pixels surrounding the
1285 primitive). These pixels will overwrite the other image's pixels,
1286 affectively clearing those, while the primitive only overwrites
1291 \o \inlineimage qpainter-compositiondemo.png
1294 \bold {Composition Modes Example}
1296 The \l {painting/composition}{Composition Modes} example, available in
1297 Qt's examples directory, allows you to experiment with the various
1298 composition modes and see the results immediately.
1302 \section1 Limitations
1305 If you are using coordinates with Qt's raster-based paint engine, it is
1306 important to note that, while coordinates greater than +/- 2\sup 15 can
1307 be used, any painting performed with coordinates outside this range is not
1308 guaranteed to be shown; the drawing may be clipped. This is due to the
1309 use of \c{short int} in the implementation.
1311 The outlines generated by Qt's stroker are only an approximation when dealing
1312 with curved shapes. It is in most cases impossible to represent the outline of
1313 a bezier curve segment using another bezier curve segment, and so Qt approximates
1314 the curve outlines by using several smaller curves. For performance reasons there
1315 is a limit to how many curves Qt uses for these outlines, and thus when using
1316 large pen widths or scales the outline error increases. To generate outlines with
1317 smaller errors it is possible to use the QPainterPathStroker class, which has the
1318 setCurveThreshold member function which let's the user specify the error tolerance.
1319 Another workaround is to convert the paths to polygons first and then draw the
1322 \section1 Performance
1324 QPainter is a rich framework that allows developers to do a great
1325 variety of graphical operations, such as gradients, composition
1326 modes and vector graphics. And QPainter can do this across a
1327 variety of different hardware and software stacks. Naturally the
1328 underlying combination of hardware and software has some
1329 implications for performance, and ensuring that every single
1330 operation is fast in combination with all the various combinations
1331 of composition modes, brushes, clipping, transformation, etc, is
1332 close to an impossible task because of the number of
1333 permutations. As a compromise we have selected a subset of the
1334 QPainter API and backends, where performance is guaranteed to be as
1335 good as we can sensibly get it for the given combination of
1336 hardware and software.
1338 The backends we focus on as high-performance engines are:
1342 \o Raster - This backend implements all rendering in pure software
1343 and is always used to render into QImages. For optimal performance
1344 only use the format types QImage::Format_ARGB32_Premultiplied,
1345 QImage::Format_RGB32 or QImage::Format_RGB16. Any other format,
1346 including QImage::Format_ARGB32, has significantly worse
1347 performance. This engine is used by default for QWidget and QPixmap.
1349 \o OpenGL 2.0 (ES) - This backend is the primary backend for
1350 hardware accelerated graphics. It can be run on desktop machines
1351 and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0
1352 specification. This includes most graphics chips produced in the
1353 last couple of years. The engine can be enabled by using QPainter
1354 onto a QGLWidget or by passing \c {-graphicssystem opengl} on the
1355 command line when the underlying system supports it.
1357 \o OpenVG - This backend implements the Khronos standard for 2D
1358 and Vector Graphics. It is primarily for embedded devices with
1359 hardware support for OpenVG. The engine can be enabled by
1360 passing \c {-graphicssystem openvg} on the command line when
1361 the underlying system supports it.
1365 These operations are:
1369 \o Simple transformations, meaning translation and scaling, pluss
1370 0, 90, 180, 270 degree rotations.
1372 \o \c drawPixmap() in combination with simple transformations and
1373 opacity with non-smooth transformation mode
1374 (\c QPainter::SmoothPixmapTransform not enabled as a render hint).
1376 \o Rectangle fills with solid color, two-color linear gradients
1377 and simple transforms.
1379 \o Rectangular clipping with simple transformations and intersect
1382 \o Composition Modes \c QPainter::CompositionMode_Source and
1383 QPainter::CompositionMode_SourceOver
1385 \o Rounded rectangle filling using solid color and two-color
1386 linear gradients fills.
1388 \o 3x3 patched pixmaps, via qDrawBorderPixmap.
1392 This list gives an indication of which features to safely use in
1393 an application where performance is critical. For certain setups,
1394 other operations may be fast too, but before making extensive use
1395 of them, it is recommended to benchmark and verify them on the
1396 system where the software will run in the end. There are also
1397 cases where expensive operations are ok to use, for instance when
1398 the result is cached in a QPixmap.
1400 \sa QPaintDevice, QPaintEngine, {QtSvg Module}, {Basic Drawing Example},
1401 {Drawing Utility Functions}
1405 \enum QPainter::RenderHint
1407 Renderhints are used to specify flags to QPainter that may or
1408 may not be respected by any given engine.
1410 \value Antialiasing Indicates that the engine should antialias
1411 edges of primitives if possible.
1413 \value TextAntialiasing Indicates that the engine should antialias
1414 text if possible. To forcibly disable antialiasing for text, do not
1415 use this hint. Instead, set QFont::NoAntialias on your font's style
1418 \value SmoothPixmapTransform Indicates that the engine should use
1419 a smooth pixmap transformation algorithm (such as bilinear) rather
1420 than nearest neighbor.
1422 \value HighQualityAntialiasing An OpenGL-specific rendering hint
1423 indicating that the engine should use fragment programs and offscreen
1424 rendering for antialiasing.
1426 \value NonCosmeticDefaultPen The engine should interpret pens with a width
1427 of 0 (which otherwise enables QPen::isCosmetic()) as being a non-cosmetic
1428 pen with a width of 1.
1430 \sa renderHints(), setRenderHint(), {QPainter#Rendering
1431 Quality}{Rendering Quality}, {Concentric Circles Example}
1436 Constructs a painter.
1441 QPainter::QPainter()
1442 : d_ptr(new QPainterPrivate(this))
1447 \fn QPainter::QPainter(QPaintDevice *device)
1449 Constructs a painter that begins painting the paint \a device
1452 This constructor is convenient for short-lived painters, e.g. in a
1453 QWidget::paintEvent() and should be used only once. The
1454 constructor calls begin() for you and the QPainter destructor
1455 automatically calls end().
1457 Here's an example using begin() and end():
1458 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 1
1460 The same example using this constructor:
1461 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 2
1463 Since the constructor cannot provide feedback when the initialization
1464 of the painter failed you should rather use begin() and end() to paint
1465 on external devices, e.g. printers.
1470 QPainter::QPainter(QPaintDevice *pd)
1474 if (!QPainterPrivate::attachPainterPrivate(this, pd)) {
1475 d_ptr.reset(new QPainterPrivate(this));
1482 Destroys the painter.
1484 QPainter::~QPainter()
1486 d_ptr->inDestructor = true;
1490 else if (d_ptr->refcount > 1)
1491 d_ptr->detachPainterPrivate(this);
1493 // don't throw anything in the destructor.
1496 // Make sure we haven't messed things up.
1497 Q_ASSERT(d_ptr->inDestructor);
1498 d_ptr->inDestructor = false;
1499 Q_ASSERT(d_ptr->refcount == 1);
1501 free(d_ptr->d_ptrs);
1506 Returns the paint device on which this painter is currently
1507 painting, or 0 if the painter is not active.
1512 QPaintDevice *QPainter::device() const
1514 Q_D(const QPainter);
1515 if (isActive() && d->engine->d_func()->currentClipDevice)
1516 return d->engine->d_func()->currentClipDevice;
1517 return d->original_device;
1521 Returns true if begin() has been called and end() has not yet been
1522 called; otherwise returns false.
1524 \sa begin(), QPaintDevice::paintingActive()
1527 bool QPainter::isActive() const
1529 Q_D(const QPainter);
1534 Initializes the painters pen, background and font to the same as
1535 the given \a paint device.
1539 \sa begin(), {QPainter#Settings}{Settings}
1541 void QPainter::initFrom(const QPaintDevice *device)
1543 Q_ASSERT_X(device, "QPainter::initFrom(const QPaintDevice *device)", "QPaintDevice cannot be 0");
1546 qWarning("QPainter::initFrom: Painter not active, aborted");
1553 d->extended->penChanged();
1554 } else if (d->engine) {
1555 d->engine->setDirty(QPaintEngine::DirtyPen);
1556 d->engine->setDirty(QPaintEngine::DirtyBrush);
1557 d->engine->setDirty(QPaintEngine::DirtyFont);
1563 Saves the current painter state (pushes the state onto a stack). A
1564 save() must be followed by a corresponding restore(); the end()
1565 function unwinds the stack.
1570 void QPainter::save()
1572 #ifdef QT_DEBUG_DRAW
1573 if (qt_show_painter_debug_output)
1574 printf("QPainter::save()\n");
1578 qWarning("QPainter::save: Painter not active");
1583 d->state = d->extended->createState(d->states.back());
1584 d->extended->setState(d->state);
1586 d->updateState(d->state);
1587 d->state = new QPainterState(d->states.back());
1588 d->engine->state = d->state;
1590 d->states.push_back(d->state);
1594 Restores the current painter state (pops a saved state off the
1600 void QPainter::restore()
1602 #ifdef QT_DEBUG_DRAW
1603 if (qt_show_painter_debug_output)
1604 printf("QPainter::restore()\n");
1607 if (d->states.size()<=1) {
1608 qWarning("QPainter::restore: Unbalanced save/restore");
1610 } else if (!d->engine) {
1611 qWarning("QPainter::restore: Painter not active");
1615 QPainterState *tmp = d->state;
1616 d->states.pop_back();
1617 d->state = d->states.back();
1621 d->checkEmulation();
1622 d->extended->setState(d->state);
1627 // trigger clip update if the clip path/region has changed since
1629 if (!d->state->clipInfo.isEmpty()
1630 && (tmp->changeFlags & (QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipPath))) {
1631 // reuse the tmp state to avoid any extra allocs...
1632 tmp->dirtyFlags = QPaintEngine::DirtyClipPath;
1633 tmp->clipOperation = Qt::NoClip;
1634 tmp->clipPath = QPainterPath();
1635 d->engine->updateState(*tmp);
1636 // replay the list of clip states,
1637 for (int i=0; i<d->state->clipInfo.size(); ++i) {
1638 const QPainterClipInfo &info = d->state->clipInfo.at(i);
1639 tmp->matrix = info.matrix;
1640 tmp->matrix *= d->state->redirectionMatrix;
1641 tmp->clipOperation = info.operation;
1642 if (info.clipType == QPainterClipInfo::RectClip) {
1643 tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform;
1644 tmp->clipRegion = info.rect;
1645 } else if (info.clipType == QPainterClipInfo::RegionClip) {
1646 tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform;
1647 tmp->clipRegion = info.region;
1648 } else { // clipType == QPainterClipInfo::PathClip
1649 tmp->dirtyFlags = QPaintEngine::DirtyClipPath | QPaintEngine::DirtyTransform;
1650 tmp->clipPath = info.path;
1652 d->engine->updateState(*tmp);
1656 //Since we've updated the clip region anyway, pretend that the clip path hasn't changed:
1657 d->state->dirtyFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion);
1658 tmp->changeFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion);
1659 tmp->changeFlags |= QPaintEngine::DirtyTransform;
1662 d->updateState(d->state);
1669 \fn bool QPainter::begin(QPaintDevice *device)
1671 Begins painting the paint \a device and returns true if
1672 successful; otherwise returns false.
1674 Notice that all painter settings (setPen(), setBrush() etc.) are reset
1675 to default values when begin() is called.
1677 The errors that can occur are serious problems, such as these:
1679 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 3
1681 Note that most of the time, you can use one of the constructors
1682 instead of begin(), and that end() is automatically done at
1685 \warning A paint device can only be painted by one painter at a
1688 \warning Painting on a QImage with the format
1689 QImage::Format_Indexed8 is not supported.
1691 \sa end(), QPainter()
1694 static inline void qt_cleanup_painter_state(QPainterPrivate *d)
1703 bool QPainter::begin(QPaintDevice *pd)
1707 if (pd->painters > 0) {
1708 qWarning("QPainter::begin: A paint device can only be painted by one painter at a time.");
1712 if (d_ptr->engine) {
1713 qWarning("QPainter::begin: Painter already active");
1717 if (QPainterPrivate::attachPainterPrivate(this, pd))
1722 d->helper_device = pd;
1723 d->original_device = pd;
1725 QPoint redirectionOffset;
1726 QPaintDevice *rpd = pd->redirected(&redirectionOffset);
1730 #ifdef QT_DEBUG_DRAW
1731 if (qt_show_painter_debug_output)
1732 printf("QPainter::begin(), device=%p, type=%d\n", pd, pd->devType());
1735 if (pd->devType() == QInternal::Pixmap)
1736 static_cast<QPixmap *>(pd)->detach();
1737 else if (pd->devType() == QInternal::Image)
1738 static_cast<QImage *>(pd)->detach();
1740 d->engine = pd->paintEngine();
1743 qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType());
1749 d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : 0;
1750 if (d->emulationEngine)
1751 d->emulationEngine->real_engine = d->extended;
1753 // Setup new state...
1754 Q_ASSERT(!d->state);
1755 d->state = d->extended ? d->extended->createState(0) : new QPainterState;
1756 d->state->painter = this;
1757 d->states.push_back(d->state);
1759 d->state->redirectionMatrix.translate(-redirectionOffset.x(), -redirectionOffset.y());
1760 d->state->brushOrigin = QPointF();
1762 // Slip a painter state into the engine before we do any other operations
1764 d->extended->setState(d->state);
1766 d->engine->state = d->state;
1768 switch (pd->devType()) {
1770 // is this needed any more??
1771 case QInternal::Widget:
1773 const QWidget *widget = static_cast<const QWidget *>(pd);
1776 const bool paintOutsidePaintEvent = widget->testAttribute(Qt::WA_PaintOutsidePaintEvent);
1777 const bool inPaintEvent = widget->testAttribute(Qt::WA_WState_InPaintEvent);
1779 // Adjust offset for alien widgets painting outside the paint event.
1780 if (!inPaintEvent && paintOutsidePaintEvent && !widget->internalWinId()
1781 && widget->testAttribute(Qt::WA_WState_Created)) {
1782 const QPoint offset = widget->mapTo(widget->nativeParentWidget(), QPoint());
1783 d->state->redirectionMatrix.translate(offset.x(), offset.y());
1788 case QInternal::Pixmap:
1790 QPixmap *pm = static_cast<QPixmap *>(pd);
1793 qWarning("QPainter::begin: Cannot paint on a null pixmap");
1794 qt_cleanup_painter_state(d);
1798 if (pm->depth() == 1) {
1799 d->state->pen = QPen(Qt::color1);
1800 d->state->brush = QBrush(Qt::color0);
1804 case QInternal::Image:
1806 QImage *img = static_cast<QImage *>(pd);
1808 if (img->isNull()) {
1809 qWarning("QPainter::begin: Cannot paint on a null image");
1810 qt_cleanup_painter_state(d);
1812 } else if (img->format() == QImage::Format_Indexed8) {
1813 // Painting on indexed8 images is not supported.
1814 qWarning("QPainter::begin: Cannot paint on an image with the QImage::Format_Indexed8 format");
1815 qt_cleanup_painter_state(d);
1818 if (img->depth() == 1) {
1819 d->state->pen = QPen(Qt::color1);
1820 d->state->brush = QBrush(Qt::color0);
1827 if (d->state->ww == 0) // For compat with 3.x painter defaults
1828 d->state->ww = d->state->wh = d->state->vw = d->state->vh = 1024;
1830 d->engine->setPaintDevice(pd);
1832 bool begun = d->engine->begin(pd);
1834 qWarning("QPainter::begin(): Returned false");
1835 if (d->engine->isActive()) {
1838 qt_cleanup_painter_state(d);
1842 d->engine->setActive(begun);
1845 // Copy painter properties from original paint device,
1846 // required for QPixmap::grabWidget()
1847 if (d->original_device->devType() == QInternal::Widget) {
1848 initFrom(d->original_device);
1850 d->state->layoutDirection = Qt::LayoutDirectionAuto;
1851 // make sure we have a font compatible with the paintdevice
1852 d->state->deviceFont = d->state->font = QFont(d->state->deviceFont, device());
1855 QRect systemRect = d->engine->systemRect();
1856 if (!systemRect.isEmpty()) {
1857 d->state->ww = d->state->vw = systemRect.width();
1858 d->state->wh = d->state->vh = systemRect.height();
1860 d->state->ww = d->state->vw = pd->metric(QPaintDevice::PdmWidth);
1861 d->state->wh = d->state->vh = pd->metric(QPaintDevice::PdmHeight);
1864 const QPoint coordinateOffset = d->engine->coordinateOffset();
1865 d->state->redirectionMatrix.translate(-coordinateOffset.x(), -coordinateOffset.y());
1867 Q_ASSERT(d->engine->isActive());
1869 if (!d->state->redirectionMatrix.isIdentity())
1872 Q_ASSERT(d->engine->isActive());
1873 d->state->renderHints = QPainter::TextAntialiasing;
1874 ++d->device->painters;
1876 d->state->emulationSpecifier = 0;
1882 Ends painting. Any resources used while painting are released. You
1883 don't normally need to call this since it is called by the
1886 Returns true if the painter is no longer active; otherwise returns false.
1888 \sa begin(), isActive()
1891 bool QPainter::end()
1893 #ifdef QT_DEBUG_DRAW
1894 if (qt_show_painter_debug_output)
1895 printf("QPainter::end()\n");
1900 qWarning("QPainter::end: Painter not active, aborted");
1901 qt_cleanup_painter_state(d);
1905 if (d->refcount > 1) {
1906 d->detachPainterPrivate(this);
1912 if (d->engine->isActive()) {
1913 ended = d->engine->end();
1916 --d->device->painters;
1917 if (d->device->painters == 0) {
1918 d->engine->setPaintDevice(0);
1919 d->engine->setActive(false);
1923 if (d->states.size() > 1) {
1924 qWarning("QPainter::end: Painter ended with %d saved states",
1928 if (d->engine->autoDestruct()) {
1932 if (d->emulationEngine) {
1933 delete d->emulationEngine;
1934 d->emulationEngine = 0;
1941 qt_cleanup_painter_state(d);
1948 Returns the paint engine that the painter is currently operating
1949 on if the painter is active; otherwise 0.
1953 QPaintEngine *QPainter::paintEngine() const
1955 Q_D(const QPainter);
1962 Flushes the painting pipeline and prepares for the user issuing commands
1963 directly to the underlying graphics context. Must be followed by a call to
1964 endNativePainting().
1966 Note that only the states the underlying paint engine changes will be reset
1967 to their respective default states. The states we reset may change from
1968 release to release. The following states are currently reset in the OpenGL
1972 \i blending is disabled
1973 \i the depth, stencil and scissor tests are disabled
1974 \i the active texture unit is reset to 0
1975 \i the depth mask, depth function and the clear depth are reset to their
1977 \i the stencil mask, stencil operation and stencil function are reset to
1978 their default values
1979 \i the current color is reset to solid white
1982 If, for example, the OpenGL polygon mode is changed by the user inside a
1983 beginNativePaint()/endNativePainting() block, it will not be reset to the
1984 default state by endNativePainting(). Here is an example that shows
1985 intermixing of painter commands and raw OpenGL commands:
1987 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 21
1989 \sa endNativePainting()
1991 void QPainter::beginNativePainting()
1995 qWarning("QPainter::beginNativePainting: Painter not active");
2000 d->extended->beginNativePainting();
2006 Restores the painter after manually issuing native painting commands. Lets
2007 the painter restore any native state that it relies on before calling any
2008 other painter commands.
2010 \sa beginNativePainting()
2012 void QPainter::endNativePainting()
2014 Q_D(const QPainter);
2016 qWarning("QPainter::beginNativePainting: Painter not active");
2021 d->extended->endNativePainting();
2023 d->engine->syncState();
2027 Returns the font metrics for the painter if the painter is
2028 active. Otherwise, the return value is undefined.
2030 \sa font(), isActive(), {QPainter#Settings}{Settings}
2033 QFontMetrics QPainter::fontMetrics() const
2035 Q_D(const QPainter);
2037 qWarning("QPainter::fontMetrics: Painter not active");
2038 return QFontMetrics(QFont());
2040 return QFontMetrics(d->state->font);
2045 Returns the font info for the painter if the painter is
2046 active. Otherwise, the return value is undefined.
2048 \sa font(), isActive(), {QPainter#Settings}{Settings}
2051 QFontInfo QPainter::fontInfo() const
2053 Q_D(const QPainter);
2055 qWarning("QPainter::fontInfo: Painter not active");
2056 return QFontInfo(QFont());
2058 return QFontInfo(d->state->font);
2064 Returns the opacity of the painter. The default value is
2068 qreal QPainter::opacity() const
2070 Q_D(const QPainter);
2072 qWarning("QPainter::opacity: Painter not active");
2075 return d->state->opacity;
2081 Sets the opacity of the painter to \a opacity. The value should
2082 be in the range 0.0 to 1.0, where 0.0 is fully transparent and
2083 1.0 is fully opaque.
2085 Opacity set on the painter will apply to all drawing operations
2089 void QPainter::setOpacity(qreal opacity)
2094 qWarning("QPainter::setOpacity: Painter not active");
2098 opacity = qMin(qreal(1), qMax(qreal(0), opacity));
2100 if (opacity == d->state->opacity)
2103 d->state->opacity = opacity;
2106 d->extended->opacityChanged();
2108 d->state->dirtyFlags |= QPaintEngine::DirtyOpacity;
2113 Returns the currently set brush origin.
2115 \sa setBrushOrigin(), {QPainter#Settings}{Settings}
2118 QPoint QPainter::brushOrigin() const
2120 Q_D(const QPainter);
2122 qWarning("QPainter::brushOrigin: Painter not active");
2125 return QPointF(d->state->brushOrigin).toPoint();
2129 \fn void QPainter::setBrushOrigin(const QPointF &position)
2131 Sets the brush origin to \a position.
2133 The brush origin specifies the (0, 0) coordinate of the painter's
2136 Note that while the brushOrigin() was necessary to adopt the
2137 parent's background for a widget in Qt 3, this is no longer the
2138 case since the Qt 4 painter doesn't paint the background unless
2139 you explicitly tell it to do so by setting the widget's \l
2140 {QWidget::autoFillBackground}{autoFillBackground} property to
2143 \sa brushOrigin(), {QPainter#Settings}{Settings}
2146 void QPainter::setBrushOrigin(const QPointF &p)
2149 #ifdef QT_DEBUG_DRAW
2150 if (qt_show_painter_debug_output)
2151 printf("QPainter::setBrushOrigin(), (%.2f,%.2f)\n", p.x(), p.y());
2155 qWarning("QPainter::setBrushOrigin: Painter not active");
2159 d->state->brushOrigin = p;
2162 d->extended->brushOriginChanged();
2166 d->state->dirtyFlags |= QPaintEngine::DirtyBrushOrigin;
2170 \fn void QPainter::setBrushOrigin(const QPoint &position)
2173 Sets the brush's origin to the given \a position.
2177 \fn void QPainter::setBrushOrigin(int x, int y)
2181 Sets the brush's origin to point (\a x, \a y).
2185 \enum QPainter::CompositionMode
2187 Defines the modes supported for digital image compositing.
2188 Composition modes are used to specify how the pixels in one image,
2189 the source, are merged with the pixel in another image, the
2192 Please note that the bitwise raster operation modes, denoted with
2193 a RasterOp prefix, are only natively supported in the X11 and
2194 raster paint engines. This means that the only way to utilize
2195 these modes on the Mac is via a QImage. The RasterOp denoted blend
2196 modes are \e not supported for pens and brushes with alpha
2197 components. Also, turning on the QPainter::Antialiasing render
2198 hint will effectively disable the RasterOp modes.
2201 \image qpainter-compositionmode1.png
2202 \image qpainter-compositionmode2.png
2204 The most common type is SourceOver (often referred to as just
2205 alpha blending) where the source pixel is blended on top of the
2206 destination pixel in such a way that the alpha component of the
2207 source defines the translucency of the pixel.
2209 When the paint device is a QImage, the image format must be set to
2210 \l {QImage::Format}{Format_ARGB32Premultiplied} or
2211 \l {QImage::Format}{Format_ARGB32} for the composition modes to have
2212 any effect. For performance the premultiplied version is the preferred
2215 When a composition mode is set it applies to all painting
2216 operator, pens, brushes, gradients and pixmap/image drawing.
2218 \value CompositionMode_SourceOver This is the default mode. The
2219 alpha of the source is used to blend the pixel on top of the
2222 \value CompositionMode_DestinationOver The alpha of the
2223 destination is used to blend it on top of the source pixels. This
2224 mode is the inverse of CompositionMode_SourceOver.
2226 \value CompositionMode_Clear The pixels in the destination are
2227 cleared (set to fully transparent) independent of the source.
2229 \value CompositionMode_Source The output is the source
2230 pixel. (This means a basic copy operation and is identical to
2231 SourceOver when the source pixel is opaque).
2233 \value CompositionMode_Destination The output is the destination
2234 pixel. This means that the blending has no effect. This mode is
2235 the inverse of CompositionMode_Source.
2237 \value CompositionMode_SourceIn The output is the source, where
2238 the alpha is reduced by that of the destination.
2240 \value CompositionMode_DestinationIn The output is the
2241 destination, where the alpha is reduced by that of the
2242 source. This mode is the inverse of CompositionMode_SourceIn.
2244 \value CompositionMode_SourceOut The output is the source, where
2245 the alpha is reduced by the inverse of destination.
2247 \value CompositionMode_DestinationOut The output is the
2248 destination, where the alpha is reduced by the inverse of the
2249 source. This mode is the inverse of CompositionMode_SourceOut.
2251 \value CompositionMode_SourceAtop The source pixel is blended on
2252 top of the destination, with the alpha of the source pixel reduced
2253 by the alpha of the destination pixel.
2255 \value CompositionMode_DestinationAtop The destination pixel is
2256 blended on top of the source, with the alpha of the destination
2257 pixel is reduced by the alpha of the destination pixel. This mode
2258 is the inverse of CompositionMode_SourceAtop.
2260 \value CompositionMode_Xor The source, whose alpha is reduced with
2261 the inverse of the destination alpha, is merged with the
2262 destination, whose alpha is reduced by the inverse of the source
2263 alpha. CompositionMode_Xor is not the same as the bitwise Xor.
2265 \value CompositionMode_Plus Both the alpha and color of the source
2266 and destination pixels are added together.
2268 \value CompositionMode_Multiply The output is the source color
2269 multiplied by the destination. Multiplying a color with white
2270 leaves the color unchanged, while multiplying a color
2271 with black produces black.
2273 \value CompositionMode_Screen The source and destination colors
2274 are inverted and then multiplied. Screening a color with white
2275 produces white, whereas screening a color with black leaves the
2278 \value CompositionMode_Overlay Multiplies or screens the colors
2279 depending on the destination color. The destination color is mixed
2280 with the source color to reflect the lightness or darkness of the
2283 \value CompositionMode_Darken The darker of the source and
2284 destination colors is selected.
2286 \value CompositionMode_Lighten The lighter of the source and
2287 destination colors is selected.
2289 \value CompositionMode_ColorDodge The destination color is
2290 brightened to reflect the source color. A black source color
2291 leaves the destination color unchanged.
2293 \value CompositionMode_ColorBurn The destination color is darkened
2294 to reflect the source color. A white source color leaves the
2295 destination color unchanged.
2297 \value CompositionMode_HardLight Multiplies or screens the colors
2298 depending on the source color. A light source color will lighten
2299 the destination color, whereas a dark source color will darken the
2302 \value CompositionMode_SoftLight Darkens or lightens the colors
2303 depending on the source color. Similar to
2304 CompositionMode_HardLight.
2306 \value CompositionMode_Difference Subtracts the darker of the
2307 colors from the lighter. Painting with white inverts the
2308 destination color, whereas painting with black leaves the
2309 destination color unchanged.
2311 \value CompositionMode_Exclusion Similar to
2312 CompositionMode_Difference, but with a lower contrast. Painting
2313 with white inverts the destination color, whereas painting with
2314 black leaves the destination color unchanged.
2316 \value RasterOp_SourceOrDestination Does a bitwise OR operation on
2317 the source and destination pixels (src OR dst).
2319 \value RasterOp_SourceAndDestination Does a bitwise AND operation
2320 on the source and destination pixels (src AND dst).
2322 \value RasterOp_SourceXorDestination Does a bitwise XOR operation
2323 on the source and destination pixels (src XOR dst).
2325 \value RasterOp_NotSourceAndNotDestination Does a bitwise NOR
2326 operation on the source and destination pixels ((NOT src) AND (NOT
2329 \value RasterOp_NotSourceOrNotDestination Does a bitwise NAND
2330 operation on the source and destination pixels ((NOT src) OR (NOT
2333 \value RasterOp_NotSourceXorDestination Does a bitwise operation
2334 where the source pixels are inverted and then XOR'ed with the
2335 destination ((NOT src) XOR dst).
2337 \value RasterOp_NotSource Does a bitwise operation where the
2338 source pixels are inverted (NOT src).
2340 \value RasterOp_NotSourceAndDestination Does a bitwise operation
2341 where the source is inverted and then AND'ed with the destination
2342 ((NOT src) AND dst).
2344 \value RasterOp_SourceAndNotDestination Does a bitwise operation
2345 where the source is AND'ed with the inverted destination pixels
2346 (src AND (NOT dst)).
2348 \sa compositionMode(), setCompositionMode(), {QPainter#Composition
2349 Modes}{Composition Modes}, {Image Composition Example}
2353 Sets the composition mode to the given \a mode.
2355 \warning Only a QPainter operating on a QImage fully supports all
2356 composition modes. The RasterOp modes are supported for X11 as
2357 described in compositionMode().
2359 \sa compositionMode()
2361 void QPainter::setCompositionMode(CompositionMode mode)
2365 qWarning("QPainter::setCompositionMode: Painter not active");
2368 if (d->state->composition_mode == mode)
2371 d->state->composition_mode = mode;
2372 d->extended->compositionModeChanged();
2376 if (mode >= QPainter::RasterOp_SourceOrDestination) {
2377 if (!d->engine->hasFeature(QPaintEngine::RasterOpModes)) {
2378 qWarning("QPainter::setCompositionMode: "
2379 "Raster operation modes not supported on device");
2382 } else if (mode >= QPainter::CompositionMode_Plus) {
2383 if (!d->engine->hasFeature(QPaintEngine::BlendModes)) {
2384 qWarning("QPainter::setCompositionMode: "
2385 "Blend modes not supported on device");
2388 } else if (!d->engine->hasFeature(QPaintEngine::PorterDuff)) {
2389 if (mode != CompositionMode_Source && mode != CompositionMode_SourceOver) {
2390 qWarning("QPainter::setCompositionMode: "
2391 "PorterDuff modes not supported on device");
2396 d->state->composition_mode = mode;
2397 d->state->dirtyFlags |= QPaintEngine::DirtyCompositionMode;
2401 Returns the current composition mode.
2403 \sa CompositionMode, setCompositionMode()
2405 QPainter::CompositionMode QPainter::compositionMode() const
2407 Q_D(const QPainter);
2409 qWarning("QPainter::compositionMode: Painter not active");
2410 return QPainter::CompositionMode_SourceOver;
2412 return d->state->composition_mode;
2416 Returns the current background brush.
2418 \sa setBackground(), {QPainter#Settings}{Settings}
2421 const QBrush &QPainter::background() const
2423 Q_D(const QPainter);
2425 qWarning("QPainter::background: Painter not active");
2426 return d->fakeState()->brush;
2428 return d->state->bgBrush;
2433 Returns true if clipping has been set; otherwise returns false.
2435 \sa setClipping(), {QPainter#Clipping}{Clipping}
2438 bool QPainter::hasClipping() const
2440 Q_D(const QPainter);
2442 qWarning("QPainter::hasClipping: Painter not active");
2445 return d->state->clipEnabled && d->state->clipOperation != Qt::NoClip;
2450 Enables clipping if \a enable is true, or disables clipping if \a
2453 \sa hasClipping(), {QPainter#Clipping}{Clipping}
2456 void QPainter::setClipping(bool enable)
2459 #ifdef QT_DEBUG_DRAW
2460 if (qt_show_painter_debug_output)
2461 printf("QPainter::setClipping(), enable=%s, was=%s\n",
2462 enable ? "on" : "off",
2463 hasClipping() ? "on" : "off");
2466 qWarning("QPainter::setClipping: Painter not active, state will be reset by begin");
2470 if (hasClipping() == enable)
2473 // we can't enable clipping if we don't have a clip
2475 && (d->state->clipInfo.isEmpty() || d->state->clipInfo.last().operation == Qt::NoClip))
2477 d->state->clipEnabled = enable;
2480 d->extended->clipEnabledChanged();
2484 d->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled;
2485 d->updateState(d->state);
2490 Returns the currently set clip region. Note that the clip region
2491 is given in logical coordinates.
2493 \warning QPainter does not store the combined clip explicitly as
2494 this is handled by the underlying QPaintEngine, so the path is
2495 recreated on demand and transformed to the current logical
2496 coordinate system. This is potentially an expensive operation.
2498 \sa setClipRegion(), clipPath(), setClipping()
2501 QRegion QPainter::clipRegion() const
2503 Q_D(const QPainter);
2505 qWarning("QPainter::clipRegion: Painter not active");
2510 bool lastWasNothing = true;
2513 const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2515 // ### Falcon: Use QPainterPath
2516 for (int i=0; i<d->state->clipInfo.size(); ++i) {
2517 const QPainterClipInfo &info = d->state->clipInfo.at(i);
2518 switch (info.clipType) {
2520 case QPainterClipInfo::RegionClip: {
2521 QTransform matrix = (info.matrix * d->invMatrix);
2522 if (lastWasNothing) {
2523 region = info.region * matrix;
2524 lastWasNothing = false;
2527 if (info.operation == Qt::IntersectClip)
2528 region &= info.region * matrix;
2529 else if (info.operation == Qt::NoClip) {
2530 lastWasNothing = true;
2533 region = info.region * matrix;
2537 case QPainterClipInfo::PathClip: {
2538 QTransform matrix = (info.matrix * d->invMatrix);
2539 if (lastWasNothing) {
2540 region = QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2541 info.path.fillRule());
2542 lastWasNothing = false;
2545 if (info.operation == Qt::IntersectClip) {
2546 region &= QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2547 info.path.fillRule());
2548 } else if (info.operation == Qt::NoClip) {
2549 lastWasNothing = true;
2552 region = QRegion((info.path * matrix).toFillPolygon().toPolygon(),
2553 info.path.fillRule());
2558 case QPainterClipInfo::RectClip: {
2559 QTransform matrix = (info.matrix * d->invMatrix);
2560 if (lastWasNothing) {
2561 region = QRegion(info.rect) * matrix;
2562 lastWasNothing = false;
2565 if (info.operation == Qt::IntersectClip) {
2566 // Use rect intersection if possible.
2567 if (matrix.type() <= QTransform::TxScale)
2568 region &= matrix.mapRect(info.rect);
2570 region &= matrix.map(QRegion(info.rect));
2571 } else if (info.operation == Qt::NoClip) {
2572 lastWasNothing = true;
2575 region = QRegion(info.rect) * matrix;
2580 case QPainterClipInfo::RectFClip: {
2581 QTransform matrix = (info.matrix * d->invMatrix);
2582 if (lastWasNothing) {
2583 region = QRegion(info.rectf.toRect()) * matrix;
2584 lastWasNothing = false;
2587 if (info.operation == Qt::IntersectClip) {
2588 // Use rect intersection if possible.
2589 if (matrix.type() <= QTransform::TxScale)
2590 region &= matrix.mapRect(info.rectf.toRect());
2592 region &= matrix.map(QRegion(info.rectf.toRect()));
2593 } else if (info.operation == Qt::NoClip) {
2594 lastWasNothing = true;
2597 region = QRegion(info.rectf.toRect()) * matrix;
2607 extern QPainterPath qt_regionToPath(const QRegion ®ion);
2610 Returns the currently clip as a path. Note that the clip path is
2611 given in logical coordinates.
2613 \warning QPainter does not store the combined clip explicitly as
2614 this is handled by the underlying QPaintEngine, so the path is
2615 recreated on demand and transformed to the current logical
2616 coordinate system. This is potentially an expensive operation.
2618 \sa setClipPath(), clipRegion(), setClipping()
2620 QPainterPath QPainter::clipPath() const
2622 Q_D(const QPainter);
2624 // ### Since we do not support path intersections and path unions yet,
2625 // we just use clipRegion() here...
2627 qWarning("QPainter::clipPath: Painter not active");
2628 return QPainterPath();
2631 // No clip, return empty
2632 if (d->state->clipInfo.size() == 0) {
2633 return QPainterPath();
2636 // Update inverse matrix, used below.
2638 const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2640 // For the simple case avoid conversion.
2641 if (d->state->clipInfo.size() == 1
2642 && d->state->clipInfo.at(0).clipType == QPainterClipInfo::PathClip) {
2643 QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix);
2644 return d->state->clipInfo.at(0).path * matrix;
2646 } else if (d->state->clipInfo.size() == 1
2647 && d->state->clipInfo.at(0).clipType == QPainterClipInfo::RectClip) {
2648 QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix);
2650 path.addRect(d->state->clipInfo.at(0).rect);
2651 return path * matrix;
2653 // Fallback to clipRegion() for now, since we don't have isect/unite for paths
2654 return qt_regionToPath(clipRegion());
2660 Returns the bounding rectangle of the current clip if there is a clip;
2661 otherwise returns an empty rectangle. Note that the clip region is
2662 given in logical coordinates.
2664 The bounding rectangle is not guaranteed to be tight.
2666 \sa setClipRect(), setClipPath(), setClipRegion()
2671 QRectF QPainter::clipBoundingRect() const
2673 Q_D(const QPainter);
2676 qWarning("QPainter::clipBoundingRect: Painter not active");
2680 // Accumulate the bounding box in device space. This is not 100%
2681 // precise, but it fits within the guarantee and it is reasonably
2684 for (int i=0; i<d->state->clipInfo.size(); ++i) {
2686 const QPainterClipInfo &info = d->state->clipInfo.at(i);
2688 if (info.clipType == QPainterClipInfo::RectClip)
2690 else if (info.clipType == QPainterClipInfo::RectFClip)
2692 else if (info.clipType == QPainterClipInfo::RegionClip)
2693 r = info.region.boundingRect();
2695 r = info.path.boundingRect();
2697 r = info.matrix.mapRect(r);
2701 else if (info.operation == Qt::IntersectClip)
2706 // Map the rectangle back into logical space using the inverse
2709 const_cast<QPainter *>(this)->d_ptr->updateInvMatrix();
2711 return d->invMatrix.mapRect(bounds);
2715 \fn void QPainter::setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
2717 Enables clipping, and sets the clip region to the given \a
2718 rectangle using the given clip \a operation. The default operation
2719 is to replace the current clip rectangle.
2721 Note that the clip rectangle is specified in logical (painter)
2724 \sa clipRegion(), setClipping(), {QPainter#Clipping}{Clipping}
2726 void QPainter::setClipRect(const QRectF &rect, Qt::ClipOperation op)
2731 if ((!d->state->clipEnabled && op != Qt::NoClip))
2732 op = Qt::ReplaceClip;
2735 qWarning("QPainter::setClipRect: Painter not active");
2738 qreal right = rect.x() + rect.width();
2739 qreal bottom = rect.y() + rect.height();
2740 qreal pts[] = { rect.x(), rect.y(),
2744 QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint);
2745 d->state->clipEnabled = true;
2746 d->extended->clip(vp, op);
2747 if (op == Qt::ReplaceClip || op == Qt::NoClip)
2748 d->state->clipInfo.clear();
2749 d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2750 d->state->clipOperation = op;
2754 if (qreal(int(rect.top())) == rect.top()
2755 && qreal(int(rect.bottom())) == rect.bottom()
2756 && qreal(int(rect.left())) == rect.left()
2757 && qreal(int(rect.right())) == rect.right())
2759 setClipRect(rect.toRect(), op);
2763 if (rect.isEmpty()) {
2764 setClipRegion(QRegion(), op);
2770 setClipPath(path, op);
2774 \fn void QPainter::setClipRect(const QRect &rectangle, Qt::ClipOperation operation)
2777 Enables clipping, and sets the clip region to the given \a rectangle using the given
2780 void QPainter::setClipRect(const QRect &rect, Qt::ClipOperation op)
2785 qWarning("QPainter::setClipRect: Painter not active");
2789 if ((!d->state->clipEnabled && op != Qt::NoClip))
2790 op = Qt::ReplaceClip;
2793 d->state->clipEnabled = true;
2794 d->extended->clip(rect, op);
2795 if (op == Qt::ReplaceClip || op == Qt::NoClip)
2796 d->state->clipInfo.clear();
2797 d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2798 d->state->clipOperation = op;
2802 if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
2803 op = Qt::ReplaceClip;
2805 d->state->clipRegion = rect;
2806 d->state->clipOperation = op;
2807 if (op == Qt::NoClip || op == Qt::ReplaceClip)
2808 d->state->clipInfo.clear();
2809 d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix);
2810 d->state->clipEnabled = true;
2811 d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled;
2812 d->updateState(d->state);
2816 \fn void QPainter::setClipRect(int x, int y, int width, int height, Qt::ClipOperation operation)
2818 Enables clipping, and sets the clip region to the rectangle beginning at (\a x, \a y)
2819 with the given \a width and \a height.
2823 \fn void QPainter::setClipRegion(const QRegion ®ion, Qt::ClipOperation operation)
2825 Sets the clip region to the given \a region using the specified clip
2826 \a operation. The default clip operation is to replace the current
2829 Note that the clip region is given in logical coordinates.
2831 \sa clipRegion(), setClipRect(), {QPainter#Clipping}{Clipping}
2833 void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op)
2836 #ifdef QT_DEBUG_DRAW
2837 QRect rect = r.boundingRect();
2838 if (qt_show_painter_debug_output)
2839 printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n",
2840 r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height());
2843 qWarning("QPainter::setClipRegion: Painter not active");
2847 if ((!d->state->clipEnabled && op != Qt::NoClip))
2848 op = Qt::ReplaceClip;
2851 d->state->clipEnabled = true;
2852 d->extended->clip(r, op);
2853 if (op == Qt::NoClip || op == Qt::ReplaceClip)
2854 d->state->clipInfo.clear();
2855 d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix);
2856 d->state->clipOperation = op;
2860 if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
2861 op = Qt::ReplaceClip;
2863 d->state->clipRegion = r;
2864 d->state->clipOperation = op;
2865 if (op == Qt::NoClip || op == Qt::ReplaceClip)
2866 d->state->clipInfo.clear();
2867 d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix);
2868 d->state->clipEnabled = true;
2869 d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled;
2870 d->updateState(d->state);
2877 Sets the transformation matrix to \a matrix and enables transformations.
2879 \note It is advisable to use setWorldTransform() instead of this function to
2880 preserve the properties of perspective transformations.
2882 If \a combine is true, then \a matrix is combined with the current
2883 transformation matrix; otherwise \a matrix replaces the current
2884 transformation matrix.
2886 If \a matrix is the identity matrix and \a combine is false, this
2887 function calls setWorldMatrixEnabled(false). (The identity matrix is the
2888 matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the
2891 The following functions can transform the coordinate system without using
2900 They operate on the painter's worldMatrix() and are implemented like this:
2902 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 4
2904 Note that when using setWorldMatrix() function you should always have
2905 \a combine be true when you are drawing into a QPicture. Otherwise
2906 it may not be possible to replay the picture with additional
2907 transformations; using the translate(), scale(), etc. convenience
2910 For more information about the coordinate system, transformations
2911 and window-viewport conversion, see \l {Coordinate System}.
2913 \sa setWorldTransform(), QTransform
2916 void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine)
2918 setWorldTransform(QTransform(matrix), combine);
2925 Returns the world transformation matrix.
2927 It is advisable to use worldTransform() because worldMatrix() does not
2928 preserve the properties of perspective transformations.
2930 \sa {QPainter#Coordinate Transformations}{Coordinate Transformations},
2934 const QMatrix &QPainter::worldMatrix() const
2936 Q_D(const QPainter);
2938 qWarning("QPainter::worldMatrix: Painter not active");
2939 return d->fakeState()->transform.toAffine();
2941 return d->state->worldMatrix.toAffine();
2947 Use setWorldTransform() instead.
2949 \sa setWorldTransform()
2952 void QPainter::setMatrix(const QMatrix &matrix, bool combine)
2954 setWorldTransform(QTransform(matrix), combine);
2960 Use worldTransform() instead.
2962 \sa worldTransform()
2965 const QMatrix &QPainter::matrix() const
2967 return worldMatrix();
2975 Returns the transformation matrix combining the current
2976 window/viewport and world transformation.
2978 It is advisable to use combinedTransform() instead of this
2979 function to preserve the properties of perspective transformations.
2981 \sa setWorldTransform(), setWindow(), setViewport()
2983 QMatrix QPainter::combinedMatrix() const
2985 return combinedTransform().toAffine();
2992 Returns the matrix that transforms from logical coordinates to
2993 device coordinates of the platform dependent paint device.
2995 \note It is advisable to use deviceTransform() instead of this
2996 function to preserve the properties of perspective transformations.
2998 This function is \e only needed when using platform painting
2999 commands on the platform dependent handle (Qt::HANDLE), and the
3000 platform does not do transformations nativly.
3002 The QPaintEngine::PaintEngineFeature enum can be queried to
3003 determine whether the platform performs the transformations or
3006 \sa worldMatrix(), QPaintEngine::hasFeature(),
3008 const QMatrix &QPainter::deviceMatrix() const
3010 Q_D(const QPainter);
3012 qWarning("QPainter::deviceMatrix: Painter not active");
3013 return d->fakeState()->transform.toAffine();
3015 return d->state->matrix.toAffine();
3021 Resets any transformations that were made using translate(), scale(),
3022 shear(), rotate(), setWorldMatrix(), setViewport() and
3025 It is advisable to use resetTransform() instead of this function
3026 to preserve the properties of perspective transformations.
3028 \sa {QPainter#Coordinate Transformations}{Coordinate
3032 void QPainter::resetMatrix()
3041 Enables transformations if \a enable is true, or disables
3042 transformations if \a enable is false. The world transformation
3043 matrix is not changed.
3045 \sa worldMatrixEnabled(), worldTransform(), {QPainter#Coordinate
3046 Transformations}{Coordinate Transformations}
3049 void QPainter::setWorldMatrixEnabled(bool enable)
3052 #ifdef QT_DEBUG_DRAW
3053 if (qt_show_painter_debug_output)
3054 printf("QPainter::setMatrixEnabled(), enable=%d\n", enable);
3058 qWarning("QPainter::setMatrixEnabled: Painter not active");
3061 if (enable == d->state->WxF)
3064 d->state->WxF = enable;
3071 Returns true if world transformation is enabled; otherwise returns
3074 \sa setWorldMatrixEnabled(), worldTransform(), {Coordinate System}
3077 bool QPainter::worldMatrixEnabled() const
3079 Q_D(const QPainter);
3081 qWarning("QPainter::worldMatrixEnabled: Painter not active");
3084 return d->state->WxF;
3090 Use setWorldMatrixEnabled() instead.
3092 \sa setWorldMatrixEnabled()
3095 void QPainter::setMatrixEnabled(bool enable)
3097 setWorldMatrixEnabled(enable);
3103 Use worldMatrixEnabled() instead
3105 \sa worldMatrixEnabled()
3108 bool QPainter::matrixEnabled() const
3110 return worldMatrixEnabled();
3114 Scales the coordinate system by (\a{sx}, \a{sy}).
3116 \sa setWorldTransform() {QPainter#Coordinate Transformations}{Coordinate
3120 void QPainter::scale(qreal sx, qreal sy)
3122 #ifdef QT_DEBUG_DRAW
3123 if (qt_show_painter_debug_output)
3124 printf("QPainter::scale(), sx=%f, sy=%f\n", sx, sy);
3128 qWarning("QPainter::scale: Painter not active");
3132 d->state->worldMatrix.scale(sx,sy);
3133 d->state->WxF = true;
3138 Shears the coordinate system by (\a{sh}, \a{sv}).
3140 \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate
3144 void QPainter::shear(qreal sh, qreal sv)
3146 #ifdef QT_DEBUG_DRAW
3147 if (qt_show_painter_debug_output)
3148 printf("QPainter::shear(), sh=%f, sv=%f\n", sh, sv);
3152 qWarning("QPainter::shear: Painter not active");
3156 d->state->worldMatrix.shear(sh, sv);
3157 d->state->WxF = true;
3162 \fn void QPainter::rotate(qreal angle)
3164 Rotates the coordinate system the given \a angle clockwise.
3166 \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate
3170 void QPainter::rotate(qreal a)
3172 #ifdef QT_DEBUG_DRAW
3173 if (qt_show_painter_debug_output)
3174 printf("QPainter::rotate(), angle=%f\n", a);
3178 qWarning("QPainter::rotate: Painter not active");
3182 d->state->worldMatrix.rotate(a);
3183 d->state->WxF = true;
3188 Translates the coordinate system by the given \a offset; i.e. the
3189 given \a offset is added to points.
3191 \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate
3194 void QPainter::translate(const QPointF &offset)
3196 qreal dx = offset.x();
3197 qreal dy = offset.y();
3198 #ifdef QT_DEBUG_DRAW
3199 if (qt_show_painter_debug_output)
3200 printf("QPainter::translate(), dx=%f, dy=%f\n", dx, dy);
3204 qWarning("QPainter::translate: Painter not active");
3208 d->state->worldMatrix.translate(dx, dy);
3209 d->state->WxF = true;
3214 \fn void QPainter::translate(const QPoint &offset)
3217 Translates the coordinate system by the given \a offset.
3221 \fn void QPainter::translate(qreal dx, qreal dy)
3224 Translates the coordinate system by the vector (\a dx, \a dy).
3228 \fn void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation operation)
3230 Enables clipping, and sets the clip path for the painter to the
3231 given \a path, with the clip \a operation.
3233 Note that the clip path is specified in logical (painter)
3236 \sa clipPath(), clipRegion(), {QPainter#Clipping}{Clipping}
3239 void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op)
3241 #ifdef QT_DEBUG_DRAW
3242 if (qt_show_painter_debug_output) {
3243 QRectF b = path.boundingRect();
3244 printf("QPainter::setClipPath(), size=%d, op=%d, bounds=[%.2f,%.2f,%.2f,%.2f]\n",
3245 path.elementCount(), op, b.x(), b.y(), b.width(), b.height());
3251 qWarning("QPainter::setClipPath: Painter not active");
3255 if ((!d->state->clipEnabled && op != Qt::NoClip))
3256 op = Qt::ReplaceClip;
3259 d->state->clipEnabled = true;
3260 d->extended->clip(path, op);
3261 if (op == Qt::NoClip || op == Qt::ReplaceClip)
3262 d->state->clipInfo.clear();
3263 d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix);
3264 d->state->clipOperation = op;
3268 if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip)
3269 op = Qt::ReplaceClip;
3271 d->state->clipPath = path;
3272 d->state->clipOperation = op;
3273 if (op == Qt::NoClip || op == Qt::ReplaceClip)
3274 d->state->clipInfo.clear();
3275 d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix);
3276 d->state->clipEnabled = true;
3277 d->state->dirtyFlags |= QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipEnabled;
3278 d->updateState(d->state);
3282 Draws the outline (strokes) the path \a path with the pen specified
3285 \sa fillPath(), {QPainter#Drawing}{Drawing}
3287 void QPainter::strokePath(const QPainterPath &path, const QPen &pen)
3292 qWarning("QPainter::strokePath: Painter not active");
3300 const QGradient *g = qpen_brush(pen).gradient();
3301 if (!g || g->coordinateMode() == QGradient::LogicalMode) {
3302 d->extended->stroke(qtVectorPathForPath(path), pen);
3307 QBrush oldBrush = d->state->brush;
3308 QPen oldPen = d->state->pen;
3311 setBrush(Qt::NoBrush);
3321 Fills the given \a path using the given \a brush. The outline is
3324 Alternatively, you can specify a QColor instead of a QBrush; the
3325 QBrush constructor (taking a QColor argument) will automatically
3326 create a solid pattern brush.
3330 void QPainter::fillPath(const QPainterPath &path, const QBrush &brush)
3335 qWarning("QPainter::fillPath: Painter not active");
3343 const QGradient *g = brush.gradient();
3344 if (!g || g->coordinateMode() == QGradient::LogicalMode) {
3345 d->extended->fill(qtVectorPathForPath(path), brush);
3350 QBrush oldBrush = d->state->brush;
3351 QPen oldPen = d->state->pen;
3364 Draws the given painter \a path using the current pen for outline
3365 and the current brush for filling.
3369 \o \inlineimage qpainter-path.png
3371 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 5
3374 \sa {painting/painterpaths}{the Painter Paths
3375 example},{painting/deform}{the Vector Deformation example}
3377 void QPainter::drawPath(const QPainterPath &path)
3379 #ifdef QT_DEBUG_DRAW
3380 QRectF pathBounds = path.boundingRect();
3381 if (qt_show_painter_debug_output)
3382 printf("QPainter::drawPath(), size=%d, [%.2f,%.2f,%.2f,%.2f]\n",
3383 path.elementCount(),
3384 pathBounds.x(), pathBounds.y(), pathBounds.width(), pathBounds.height());
3390 qWarning("QPainter::drawPath: Painter not active");
3395 d->extended->drawPath(path);
3398 d->updateState(d->state);
3400 if (d->engine->hasFeature(QPaintEngine::PainterPaths) && d->state->emulationSpecifier == 0) {
3401 d->engine->drawPath(path);
3403 d->draw_helper(path);
3408 \fn void QPainter::drawLine(const QLineF &line)
3410 Draws a line defined by \a line.
3414 \o \inlineimage qpainter-line.png
3416 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 6
3419 \sa drawLines(), drawPolyline(), {Coordinate System}
3423 \fn void QPainter::drawLine(const QLine &line)
3426 Draws a line defined by \a line.
3430 \fn void QPainter::drawLine(const QPoint &p1, const QPoint &p2)
3433 Draws a line from \a p1 to \a p2.
3437 \fn void QPainter::drawLine(const QPointF &p1, const QPointF &p2)
3440 Draws a line from \a p1 to \a p2.
3444 \fn void QPainter::drawLine(int x1, int y1, int x2, int y2)
3447 Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the
3448 current pen position to (\a x2, \a y2).
3452 \fn void QPainter::drawRect(const QRectF &rectangle)
3454 Draws the current \a rectangle with the current pen and brush.
3456 A filled rectangle has a size of \a{rectangle}.size(). A stroked
3457 rectangle has a size of \a{rectangle}.size() plus the pen width.
3461 \o \inlineimage qpainter-rectangle.png
3463 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 7
3466 \sa drawRects(), drawPolygon(), {Coordinate System}
3470 \fn void QPainter::drawRect(const QRect &rectangle)
3474 Draws the current \a rectangle with the current pen and brush.
3478 \fn void QPainter::drawRect(int x, int y, int width, int height)
3482 Draws a rectangle with upper left corner at (\a{x}, \a{y}) and
3483 with the given \a width and \a height.
3487 \fn void QPainter::drawRects(const QRectF *rectangles, int rectCount)
3489 Draws the first \a rectCount of the given \a rectangles using the
3490 current pen and brush.
3494 void QPainter::drawRects(const QRectF *rects, int rectCount)
3496 #ifdef QT_DEBUG_DRAW
3497 if (qt_show_painter_debug_output)
3498 printf("QPainter::drawRects(), count=%d\n", rectCount);
3503 qWarning("QPainter::drawRects: Painter not active");
3511 d->extended->drawRects(rects, rectCount);
3515 d->updateState(d->state);
3517 if (!d->state->emulationSpecifier) {
3518 d->engine->drawRects(rects, rectCount);
3522 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3523 && d->state->matrix.type() == QTransform::TxTranslate) {
3524 for (int i=0; i<rectCount; ++i) {
3525 QRectF r(rects[i].x() + d->state->matrix.dx(),
3526 rects[i].y() + d->state->matrix.dy(),
3529 d->engine->drawRects(&r, 1);
3532 if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) {
3533 for (int i=0; i<rectCount; ++i) {
3534 QPainterPath rectPath;
3535 rectPath.addRect(rects[i]);
3536 d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3539 QPainterPath rectPath;
3540 for (int i=0; i<rectCount; ++i)
3541 rectPath.addRect(rects[i]);
3542 d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3548 \fn void QPainter::drawRects(const QRect *rectangles, int rectCount)
3551 Draws the first \a rectCount of the given \a rectangles using the
3552 current pen and brush.
3554 void QPainter::drawRects(const QRect *rects, int rectCount)
3556 #ifdef QT_DEBUG_DRAW
3557 if (qt_show_painter_debug_output)
3558 printf("QPainter::drawRects(), count=%d\n", rectCount);
3563 qWarning("QPainter::drawRects: Painter not active");
3571 d->extended->drawRects(rects, rectCount);
3575 d->updateState(d->state);
3577 if (!d->state->emulationSpecifier) {
3578 d->engine->drawRects(rects, rectCount);
3582 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3583 && d->state->matrix.type() == QTransform::TxTranslate) {
3584 for (int i=0; i<rectCount; ++i) {
3585 QRectF r(rects[i].x() + d->state->matrix.dx(),
3586 rects[i].y() + d->state->matrix.dy(),
3590 d->engine->drawRects(&r, 1);
3593 if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) {
3594 for (int i=0; i<rectCount; ++i) {
3595 QPainterPath rectPath;
3596 rectPath.addRect(rects[i]);
3597 d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3600 QPainterPath rectPath;
3601 for (int i=0; i<rectCount; ++i)
3602 rectPath.addRect(rects[i]);
3604 d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw);
3610 \fn void QPainter::drawRects(const QVector<QRectF> &rectangles)
3613 Draws the given \a rectangles using the current pen and brush.
3617 \fn void QPainter::drawRects(const QVector<QRect> &rectangles)
3621 Draws the given \a rectangles using the current pen and brush.
3625 \fn void QPainter::drawPoint(const QPointF &position)
3627 Draws a single point at the given \a position using the current
3630 \sa {Coordinate System}
3634 \fn void QPainter::drawPoint(const QPoint &position)
3637 Draws a single point at the given \a position using the current
3641 /*! \fn void QPainter::drawPoint(int x, int y)
3645 Draws a single point at position (\a x, \a y).
3649 Draws the first \a pointCount points in the array \a points using
3650 the current pen's color.
3652 \sa {Coordinate System}
3654 void QPainter::drawPoints(const QPointF *points, int pointCount)
3656 #ifdef QT_DEBUG_DRAW
3657 if (qt_show_painter_debug_output)
3658 printf("QPainter::drawPoints(), count=%d\n", pointCount);
3663 qWarning("QPainter::drawPoints: Painter not active");
3667 if (pointCount <= 0)
3671 d->extended->drawPoints(points, pointCount);
3675 d->updateState(d->state);
3677 if (!d->state->emulationSpecifier) {
3678 d->engine->drawPoints(points, pointCount);
3682 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3683 && d->state->matrix.type() == QTransform::TxTranslate) {
3684 // ### use drawPoints function
3685 for (int i=0; i<pointCount; ++i) {
3686 QPointF pt(points[i].x() + d->state->matrix.dx(),
3687 points[i].y() + d->state->matrix.dy());
3688 d->engine->drawPoints(&pt, 1);
3691 QPen pen = d->state->pen;
3692 bool flat_pen = pen.capStyle() == Qt::FlatCap;
3695 pen.setCapStyle(Qt::SquareCap);
3699 for (int i=0; i<pointCount; ++i) {
3700 path.moveTo(points[i].x(), points[i].y());
3701 path.lineTo(points[i].x() + 0.0001, points[i].y());
3703 d->draw_helper(path, QPainterPrivate::StrokeDraw);
3712 Draws the first \a pointCount points in the array \a points using
3713 the current pen's color.
3716 void QPainter::drawPoints(const QPoint *points, int pointCount)
3718 #ifdef QT_DEBUG_DRAW
3719 if (qt_show_painter_debug_output)
3720 printf("QPainter::drawPoints(), count=%d\n", pointCount);
3725 qWarning("QPainter::drawPoints: Painter not active");
3729 if (pointCount <= 0)
3733 d->extended->drawPoints(points, pointCount);
3737 d->updateState(d->state);
3739 if (!d->state->emulationSpecifier) {
3740 d->engine->drawPoints(points, pointCount);
3744 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
3745 && d->state->matrix.type() == QTransform::TxTranslate) {
3746 // ### use drawPoints function
3747 for (int i=0; i<pointCount; ++i) {
3748 QPointF pt(points[i].x() + d->state->matrix.dx(),
3749 points[i].y() + d->state->matrix.dy());
3750 d->engine->drawPoints(&pt, 1);
3753 QPen pen = d->state->pen;
3754 bool flat_pen = (pen.capStyle() == Qt::FlatCap);
3757 pen.setCapStyle(Qt::SquareCap);
3761 for (int i=0; i<pointCount; ++i) {
3762 path.moveTo(points[i].x(), points[i].y());
3763 path.lineTo(points[i].x() + 0.0001, points[i].y());
3765 d->draw_helper(path, QPainterPrivate::StrokeDraw);
3772 \fn void QPainter::drawPoints(const QPolygonF &points)
3776 Draws the points in the vector \a points.
3780 \fn void QPainter::drawPoints(const QPolygon &points)
3784 Draws the points in the vector \a points.
3788 \fn void QPainter::drawPoints(const QPolygon &polygon, int index,
3794 Draws \a count points in the vector \a polygon starting on \a index
3795 using the current pen.
3797 Use drawPoints() combined with QPolygon::constData() instead.
3800 QPainter painter(this);
3801 painter.drawPoints(polygon, index, count);
3803 int pointCount = (count == -1) ? polygon.size() - index : count;
3805 QPainter painter(this);
3806 painter.drawPoints(polygon.constData() + index, pointCount);
3811 Sets the background mode of the painter to the given \a mode
3813 Qt::TransparentMode (the default) draws stippled lines and text
3814 without setting the background pixels. Qt::OpaqueMode fills these
3815 space with the current background color.
3817 Note that in order to draw a bitmap or pixmap transparently, you
3818 must use QPixmap::setMask().
3820 \sa backgroundMode(), setBackground(),
3821 {QPainter#Settings}{Settings}
3824 void QPainter::setBackgroundMode(Qt::BGMode mode)
3826 #ifdef QT_DEBUG_DRAW
3827 if (qt_show_painter_debug_output)
3828 printf("QPainter::setBackgroundMode(), mode=%d\n", mode);
3833 qWarning("QPainter::setBackgroundMode: Painter not active");
3836 if (d->state->bgMode == mode)
3839 d->state->bgMode = mode;
3841 d->checkEmulation();
3843 d->state->dirtyFlags |= QPaintEngine::DirtyBackgroundMode;
3848 Returns the current background mode.
3850 \sa setBackgroundMode(), {QPainter#Settings}{Settings}
3852 Qt::BGMode QPainter::backgroundMode() const
3854 Q_D(const QPainter);
3856 qWarning("QPainter::backgroundMode: Painter not active");
3857 return Qt::TransparentMode;
3859 return d->state->bgMode;
3866 Sets the painter's pen to have style Qt::SolidLine, width 0 and the
3870 void QPainter::setPen(const QColor &color)
3872 #ifdef QT_DEBUG_DRAW
3873 if (qt_show_painter_debug_output)
3874 printf("QPainter::setPen(), color=%04x\n", color.rgb());
3878 qWarning("QPainter::setPen: Painter not active");
3882 if (d->state->pen.style() == Qt::SolidLine
3883 && d->state->pen.widthF() == 0
3884 && d->state->pen.isSolid()
3885 && d->state->pen.color() == color)
3888 QPen pen(color.isValid() ? color : QColor(Qt::black), 0, Qt::SolidLine);
3890 d->state->pen = pen;
3892 d->extended->penChanged();
3894 d->state->dirtyFlags |= QPaintEngine::DirtyPen;
3898 Sets the painter's pen to be the given \a pen.
3900 The \a pen defines how to draw lines and outlines, and it also
3901 defines the text color.
3903 \sa pen(), {QPainter#Settings}{Settings}
3906 void QPainter::setPen(const QPen &pen)
3909 #ifdef QT_DEBUG_DRAW
3910 if (qt_show_painter_debug_output)
3911 printf("QPainter::setPen(), color=%04x, (brushStyle=%d) style=%d, cap=%d, join=%d\n",
3912 pen.color().rgb(), pen.brush().style(), pen.style(), pen.capStyle(), pen.joinStyle());
3916 qWarning("QPainter::setPen: Painter not active");
3920 if (d->state->pen == pen)
3923 d->state->pen = pen;
3926 d->checkEmulation();
3927 d->extended->penChanged();
3931 d->state->dirtyFlags |= QPaintEngine::DirtyPen;
3937 Sets the painter's pen to have the given \a style, width 0 and
3941 void QPainter::setPen(Qt::PenStyle style)
3945 qWarning("QPainter::setPen: Painter not active");
3949 if (d->state->pen.style() == style
3950 && (style == Qt::NoPen || (d->state->pen.widthF() == 0
3951 && d->state->pen.isSolid()
3952 && d->state->pen.color() == QColor(Qt::black))))
3955 // QPen(Qt::NoPen) is to avoid creating QPenData, including its brush (from the color)
3956 // Note that this works well as long as QPen(Qt::NoPen) returns a black, zero-width pen
3957 d->state->pen = (style == Qt::NoPen) ? QPen(Qt::NoPen) : QPen(Qt::black, 0, style);
3960 d->extended->penChanged();
3962 d->state->dirtyFlags |= QPaintEngine::DirtyPen;
3967 Returns the painter's current pen.
3969 \sa setPen(), {QPainter#Settings}{Settings}
3972 const QPen &QPainter::pen() const
3974 Q_D(const QPainter);
3976 qWarning("QPainter::pen: Painter not active");
3977 return d->fakeState()->pen;
3979 return d->state->pen;
3984 Sets the painter's brush to the given \a brush.
3986 The painter's brush defines how shapes are filled.
3988 \sa brush(), {QPainter#Settings}{Settings}
3991 void QPainter::setBrush(const QBrush &brush)
3993 #ifdef QT_DEBUG_DRAW
3994 if (qt_show_painter_debug_output)
3995 printf("QPainter::setBrush(), color=%04x, style=%d\n", brush.color().rgb(), brush.style());
3999 qWarning("QPainter::setBrush: Painter not active");
4003 if (d->state->brush.d == brush.d)
4007 d->state->brush = brush;
4008 d->checkEmulation();
4009 d->extended->brushChanged();
4013 d->state->brush = brush;
4014 d->state->dirtyFlags |= QPaintEngine::DirtyBrush;
4021 Sets the painter's brush to black color and the specified \a
4025 void QPainter::setBrush(Qt::BrushStyle style)
4029 qWarning("QPainter::setBrush: Painter not active");
4032 if (d->state->brush.style() == style &&
4033 (style == Qt::NoBrush
4034 || (style == Qt::SolidPattern && d->state->brush.color() == QColor(0, 0, 0))))
4036 d->state->brush = QBrush(Qt::black, style);
4038 d->extended->brushChanged();
4040 d->state->dirtyFlags |= QPaintEngine::DirtyBrush;
4044 Returns the painter's current brush.
4046 \sa QPainter::setBrush(), {QPainter#Settings}{Settings}
4049 const QBrush &QPainter::brush() const
4051 Q_D(const QPainter);
4053 qWarning("QPainter::brush: Painter not active");
4054 return d->fakeState()->brush;
4056 return d->state->brush;
4060 \fn void QPainter::setBackground(const QBrush &brush)
4062 Sets the background brush of the painter to the given \a brush.
4064 The background brush is the brush that is filled in when drawing
4065 opaque text, stippled lines and bitmaps. The background brush has
4066 no effect in transparent background mode (which is the default).
4068 \sa background(), setBackgroundMode(),
4069 {QPainter#Settings}{Settings}
4072 void QPainter::setBackground(const QBrush &bg)
4074 #ifdef QT_DEBUG_DRAW
4075 if (qt_show_painter_debug_output)
4076 printf("QPainter::setBackground(), color=%04x, style=%d\n", bg.color().rgb(), bg.style());
4081 qWarning("QPainter::setBackground: Painter not active");
4084 d->state->bgBrush = bg;
4086 d->state->dirtyFlags |= QPaintEngine::DirtyBackground;
4090 Sets the painter's font to the given \a font.
4092 This font is used by subsequent drawText() functions. The text
4093 color is the same as the pen color.
4095 If you set a font that isn't available, Qt finds a close match.
4096 font() will return what you set using setFont() and fontInfo() returns the
4097 font actually being used (which may be the same).
4099 \sa font(), drawText(), {QPainter#Settings}{Settings}
4102 void QPainter::setFont(const QFont &font)
4106 #ifdef QT_DEBUG_DRAW
4107 if (qt_show_painter_debug_output)
4108 printf("QPainter::setFont(), family=%s, pointSize=%d\n", font.family().toLatin1().constData(), font.pointSize());
4112 qWarning("QPainter::setFont: Painter not active");
4116 d->state->font = QFont(font.resolve(d->state->deviceFont), device());
4118 d->state->dirtyFlags |= QPaintEngine::DirtyFont;
4122 Returns the currently set font used for drawing text.
4124 \sa setFont(), drawText(), {QPainter#Settings}{Settings}
4126 const QFont &QPainter::font() const
4128 Q_D(const QPainter);
4130 qWarning("QPainter::font: Painter not active");
4131 return d->fakeState()->font;
4133 return d->state->font;
4139 Draws the given rectangle \a rect with rounded corners.
4141 The \a xRadius and \a yRadius arguments specify the radii
4142 of the ellipses defining the corners of the rounded rectangle.
4143 When \a mode is Qt::RelativeSize, \a xRadius and
4144 \a yRadius are specified in percentage of half the rectangle's
4145 width and height respectively, and should be in the range
4148 A filled rectangle has a size of rect.size(). A stroked rectangle
4149 has a size of rect.size() plus the pen width.
4153 \o \inlineimage qpainter-roundrect.png
4155 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 8
4158 \sa drawRect(), QPen
4160 void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
4162 #ifdef QT_DEBUG_DRAW
4163 if (qt_show_painter_debug_output)
4164 printf("QPainter::drawRoundedRect(), [%.2f,%.2f,%.2f,%.2f]\n", rect.x(), rect.y(), rect.width(), rect.height());
4171 if (xRadius <= 0 || yRadius <= 0) { // draw normal rectangle
4177 d->extended->drawRoundedRect(rect, xRadius, yRadius, mode);
4182 path.addRoundedRect(rect, xRadius, yRadius, mode);
4187 \fn void QPainter::drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius,
4188 Qt::SizeMode mode = Qt::AbsoluteSize);
4192 Draws the given rectangle \a rect with rounded corners.
4196 \fn void QPainter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius,
4197 Qt::SizeMode mode = Qt::AbsoluteSize);
4201 Draws the given rectangle \a x, \a y, \a w, \a h with rounded corners.
4207 Draws a rectangle \a r with rounded corners.
4209 The \a xRnd and \a yRnd arguments specify how rounded the corners
4210 should be. 0 is angled corners, 99 is maximum roundedness.
4212 A filled rectangle has a size of r.size(). A stroked rectangle
4213 has a size of r.size() plus the pen width.
4215 \sa drawRoundedRect()
4217 void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd)
4219 drawRoundedRect(r, xRnd, yRnd, Qt::RelativeSize);
4224 \fn void QPainter::drawRoundRect(const QRect &r, int xRnd = 25, int yRnd = 25)
4229 Draws the rectangle \a r with rounded corners.
4235 \fn QPainter::drawRoundRect(int x, int y, int w, int h, int xRnd, int yRnd)
4239 Draws the rectangle \a x, \a y, \a w, \a h with rounded corners.
4243 \fn void QPainter::drawEllipse(const QRectF &rectangle)
4245 Draws the ellipse defined by the given \a rectangle.
4247 A filled ellipse has a size of \a{rectangle}.\l
4248 {QRect::size()}{size()}. A stroked ellipse has a size of
4249 \a{rectangle}.\l {QRect::size()}{size()} plus the pen width.
4253 \o \inlineimage qpainter-ellipse.png
4255 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 9
4258 \sa drawPie(), {Coordinate System}
4260 void QPainter::drawEllipse(const QRectF &r)
4262 #ifdef QT_DEBUG_DRAW
4263 if (qt_show_painter_debug_output)
4264 printf("QPainter::drawEllipse(), [%.2f,%.2f,%.2f,%.2f]\n", r.x(), r.y(), r.width(), r.height());
4271 QRectF rect(r.normalized());
4274 d->extended->drawEllipse(rect);
4278 d->updateState(d->state);
4279 if (d->state->emulationSpecifier) {
4280 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
4281 && d->state->matrix.type() == QTransform::TxTranslate) {
4282 rect.translate(QPointF(d->state->matrix.dx(), d->state->matrix.dy()));
4285 path.addEllipse(rect);
4286 d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw);
4291 d->engine->drawEllipse(rect);
4295 \fn QPainter::drawEllipse(const QRect &rectangle)
4299 Draws the ellipse defined by the given \a rectangle.
4301 void QPainter::drawEllipse(const QRect &r)
4303 #ifdef QT_DEBUG_DRAW
4304 if (qt_show_painter_debug_output)
4305 printf("QPainter::drawEllipse(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
4312 QRect rect(r.normalized());
4315 d->extended->drawEllipse(rect);
4319 d->updateState(d->state);
4321 if (d->state->emulationSpecifier) {
4322 if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform
4323 && d->state->matrix.type() == QTransform::TxTranslate) {
4324 rect.translate(QPoint(qRound(d->state->matrix.dx()), qRound(d->state->matrix.dy())));
4327 path.addEllipse(rect);
4328 d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw);
4333 d->engine->drawEllipse(rect);
4337 \fn QPainter::drawEllipse(int x, int y, int width, int height)
4341 Draws the ellipse defined by the rectangle beginning at (\a{x},
4342 \a{y}) with the given \a width and \a height.
4348 \fn QPainter::drawEllipse(const QPointF ¢er, qreal rx, qreal ry)
4352 Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}.
4358 \fn QPainter::drawEllipse(const QPoint ¢er, int rx, int ry)
4362 Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}.
4366 \fn void QPainter::drawArc(const QRectF &rectangle, int startAngle, int spanAngle)
4368 Draws the arc defined by the given \a rectangle, \a startAngle and
4371 The \a startAngle and \a spanAngle must be specified in 1/16th of
4372 a degree, i.e. a full circle equals 5760 (16 * 360). Positive
4373 values for the angles mean counter-clockwise while negative values
4374 mean the clockwise direction. Zero degrees is at the 3 o'clock
4379 \o \inlineimage qpainter-arc.png
4381 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 10
4384 \sa drawPie(), drawChord(), {Coordinate System}
4387 void QPainter::drawArc(const QRectF &r, int a, int alen)
4389 #ifdef QT_DEBUG_DRAW
4390 if (qt_show_painter_debug_output)
4391 printf("QPainter::drawArc(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4392 r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4399 QRectF rect = r.normalized();
4402 path.arcMoveTo(rect, a/16.0);
4403 path.arcTo(rect, a/16.0, alen/16.0);
4404 strokePath(path, d->state->pen);
4407 /*! \fn void QPainter::drawArc(const QRect &rectangle, int startAngle,
4412 Draws the arc defined by the given \a rectangle, \a startAngle and
4417 \fn void QPainter::drawArc(int x, int y, int width, int height,
4418 int startAngle, int spanAngle)
4422 Draws the arc defined by the rectangle beginning at (\a x, \a y)
4423 with the specified \a width and \a height, and the given \a
4424 startAngle and \a spanAngle.
4428 \fn void QPainter::drawPie(const QRectF &rectangle, int startAngle, int spanAngle)
4430 Draws a pie defined by the given \a rectangle, \a startAngle and
4433 The pie is filled with the current brush().
4435 The startAngle and spanAngle must be specified in 1/16th of a
4436 degree, i.e. a full circle equals 5760 (16 * 360). Positive values
4437 for the angles mean counter-clockwise while negative values mean
4438 the clockwise direction. Zero degrees is at the 3 o'clock
4443 \o \inlineimage qpainter-pie.png
4445 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 11
4448 \sa drawEllipse(), drawChord(), {Coordinate System}
4450 void QPainter::drawPie(const QRectF &r, int a, int alen)
4452 #ifdef QT_DEBUG_DRAW
4453 if (qt_show_painter_debug_output)
4454 printf("QPainter::drawPie(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4455 r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4466 if (a < 0) a += (360*16);
4469 QRectF rect = r.normalized();
4472 path.moveTo(rect.center());
4473 path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/16.0, alen/16.0);
4474 path.closeSubpath();
4480 \fn void QPainter::drawPie(const QRect &rectangle, int startAngle, int spanAngle)
4483 Draws a pie defined by the given \a rectangle, \a startAngle and
4488 \fn void QPainter::drawPie(int x, int y, int width, int height, int
4489 startAngle, int spanAngle)
4493 Draws the pie defined by the rectangle beginning at (\a x, \a y) with
4494 the specified \a width and \a height, and the given \a startAngle and
4499 \fn void QPainter::drawChord(const QRectF &rectangle, int startAngle, int spanAngle)
4501 Draws the chord defined by the given \a rectangle, \a startAngle and
4502 \a spanAngle. The chord is filled with the current brush().
4504 The startAngle and spanAngle must be specified in 1/16th of a
4505 degree, i.e. a full circle equals 5760 (16 * 360). Positive values
4506 for the angles mean counter-clockwise while negative values mean
4507 the clockwise direction. Zero degrees is at the 3 o'clock
4512 \o \inlineimage qpainter-chord.png
4514 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 12
4517 \sa drawArc(), drawPie(), {Coordinate System}
4519 void QPainter::drawChord(const QRectF &r, int a, int alen)
4521 #ifdef QT_DEBUG_DRAW
4522 if (qt_show_painter_debug_output)
4523 printf("QPainter::drawChord(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n",
4524 r.x(), r.y(), r.width(), r.height(), a/16, alen/16);
4531 QRectF rect = r.normalized();
4534 path.arcMoveTo(rect, a/16.0);
4535 path.arcTo(rect, a/16.0, alen/16.0);
4536 path.closeSubpath();
4540 \fn void QPainter::drawChord(const QRect &rectangle, int startAngle, int spanAngle)
4544 Draws the chord defined by the given \a rectangle, \a startAngle and
4549 \fn void QPainter::drawChord(int x, int y, int width, int height, int
4550 startAngle, int spanAngle)
4554 Draws the chord defined by the rectangle beginning at (\a x, \a y)
4555 with the specified \a width and \a height, and the given \a
4556 startAngle and \a spanAngle.
4561 Draws the first \a lineCount lines in the array \a lines
4562 using the current pen.
4564 \sa drawLine(), drawPolyline()
4566 void QPainter::drawLines(const QLineF *lines, int lineCount)
4568 #ifdef QT_DEBUG_DRAW
4569 if (qt_show_painter_debug_output)
4570 printf("QPainter::drawLines(), line count=%d\n", lineCount);
4575 if (!d->engine || lineCount < 1)
4579 d->extended->drawLines(lines, lineCount);
4583 d->updateState(d->state);
4585 uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4587 if (lineEmulation) {
4588 if (lineEmulation == QPaintEngine::PrimitiveTransform
4589 && d->state->matrix.type() == QTransform::TxTranslate) {
4590 for (int i = 0; i < lineCount; ++i) {
4591 QLineF line = lines[i];
4592 line.translate(d->state->matrix.dx(), d->state->matrix.dy());
4593 d->engine->drawLines(&line, 1);
4596 QPainterPath linePath;
4597 for (int i = 0; i < lineCount; ++i) {
4598 linePath.moveTo(lines[i].p1());
4599 linePath.lineTo(lines[i].p2());
4601 d->draw_helper(linePath, QPainterPrivate::StrokeDraw);
4605 d->engine->drawLines(lines, lineCount);
4609 \fn void QPainter::drawLines(const QLine *lines, int lineCount)
4612 Draws the first \a lineCount lines in the array \a lines
4613 using the current pen.
4615 void QPainter::drawLines(const QLine *lines, int lineCount)
4617 #ifdef QT_DEBUG_DRAW
4618 if (qt_show_painter_debug_output)
4619 printf("QPainter::drawLine(), line count=%d\n", lineCount);
4624 if (!d->engine || lineCount < 1)
4628 d->extended->drawLines(lines, lineCount);
4632 d->updateState(d->state);
4634 uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4636 if (lineEmulation) {
4637 if (lineEmulation == QPaintEngine::PrimitiveTransform
4638 && d->state->matrix.type() == QTransform::TxTranslate) {
4639 for (int i = 0; i < lineCount; ++i) {
4640 QLineF line = lines[i];
4641 line.translate(d->state->matrix.dx(), d->state->matrix.dy());
4642 d->engine->drawLines(&line, 1);
4645 QPainterPath linePath;
4646 for (int i = 0; i < lineCount; ++i) {
4647 linePath.moveTo(lines[i].p1());
4648 linePath.lineTo(lines[i].p2());
4650 d->draw_helper(linePath, QPainterPrivate::StrokeDraw);
4654 d->engine->drawLines(lines, lineCount);
4660 Draws the first \a lineCount lines in the array \a pointPairs
4661 using the current pen. The lines are specified as pairs of points
4662 so the number of entries in \a pointPairs must be at least \a
4665 void QPainter::drawLines(const QPointF *pointPairs, int lineCount)
4667 Q_ASSERT(sizeof(QLineF) == 2*sizeof(QPointF));
4669 drawLines((QLineF*)pointPairs, lineCount);
4675 Draws the first \a lineCount lines in the array \a pointPairs
4676 using the current pen.
4678 void QPainter::drawLines(const QPoint *pointPairs, int lineCount)
4680 Q_ASSERT(sizeof(QLine) == 2*sizeof(QPoint));
4682 drawLines((QLine*)pointPairs, lineCount);
4687 \fn void QPainter::drawLines(const QVector<QPointF> &pointPairs)
4690 Draws a line for each pair of points in the vector \a pointPairs
4691 using the current pen. If there is an odd number of points in the
4692 array, the last point will be ignored.
4696 \fn void QPainter::drawLines(const QVector<QPoint> &pointPairs)
4699 Draws a line for each pair of points in the vector \a pointPairs
4700 using the current pen.
4704 \fn void QPainter::drawLines(const QVector<QLineF> &lines)
4707 Draws the set of lines defined by the list \a lines using the
4708 current pen and brush.
4712 \fn void QPainter::drawLines(const QVector<QLine> &lines)
4715 Draws the set of lines defined by the list \a lines using the
4716 current pen and brush.
4720 Draws the polyline defined by the first \a pointCount points in \a
4721 points using the current pen.
4723 Note that unlike the drawPolygon() function the last point is \e
4724 not connected to the first, neither is the polyline filled.
4729 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 13
4732 \sa drawLines(), drawPolygon(), {Coordinate System}
4734 void QPainter::drawPolyline(const QPointF *points, int pointCount)
4736 #ifdef QT_DEBUG_DRAW
4737 if (qt_show_painter_debug_output)
4738 printf("QPainter::drawPolyline(), count=%d\n", pointCount);
4742 if (!d->engine || pointCount < 2)
4746 d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
4750 d->updateState(d->state);
4752 uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4754 if (lineEmulation) {
4756 // if (lineEmulation == QPaintEngine::PrimitiveTransform
4757 // && d->state->matrix.type() == QTransform::TxTranslate) {
4759 QPainterPath polylinePath(points[0]);
4760 for (int i=1; i<pointCount; ++i)
4761 polylinePath.lineTo(points[i]);
4762 d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw);
4765 d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
4772 Draws the polyline defined by the first \a pointCount points in \a
4773 points using the current pen.
4775 void QPainter::drawPolyline(const QPoint *points, int pointCount)
4777 #ifdef QT_DEBUG_DRAW
4778 if (qt_show_painter_debug_output)
4779 printf("QPainter::drawPolyline(), count=%d\n", pointCount);
4783 if (!d->engine || pointCount < 2)
4787 d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
4791 d->updateState(d->state);
4793 uint lineEmulation = line_emulation(d->state->emulationSpecifier);
4795 if (lineEmulation) {
4797 // if (lineEmulation == QPaintEngine::PrimitiveTransform
4798 // && d->state->matrix.type() == QTransform::TxTranslate) {
4800 QPainterPath polylinePath(points[0]);
4801 for (int i=1; i<pointCount; ++i)
4802 polylinePath.lineTo(points[i]);
4803 d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw);
4806 d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode);
4811 \fn void QPainter::drawPolyline(const QPolygon &polygon, int index, int
4817 Draws the polyline defined by the \a count lines of the given \a
4818 polygon starting at \a index (\a index defaults to 0).
4820 Use drawPolyline() combined with QPolygon::constData() instead.
4823 QPainter painter(this);
4824 painter.drawPolyline(polygon, index, count);
4826 int pointCount = (count == -1) ? polygon.size() - index : count;
4828 QPainter painter(this);
4829 painter.drawPolyline(polygon.constData() + index, pointCount);
4834 \fn void QPainter::drawPolyline(const QPolygonF &points)
4838 Draws the polyline defined by the given \a points using the
4843 \fn void QPainter::drawPolyline(const QPolygon &points)
4847 Draws the polyline defined by the given \a points using the
4852 Draws the polygon defined by the first \a pointCount points in the
4853 array \a points using the current pen and brush.
4857 \o \inlineimage qpainter-polygon.png
4859 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 14
4862 The first point is implicitly connected to the last point, and the
4863 polygon is filled with the current brush().
4865 If \a fillRule is Qt::WindingFill, the polygon is filled using the
4866 winding fill algorithm. If \a fillRule is Qt::OddEvenFill, the
4867 polygon is filled using the odd-even fill algorithm. See
4868 \l{Qt::FillRule} for a more detailed description of these fill
4871 \sa drawConvexPolygon(), drawPolyline(), {Coordinate System}
4873 void QPainter::drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
4875 #ifdef QT_DEBUG_DRAW
4876 if (qt_show_painter_debug_output)
4877 printf("QPainter::drawPolygon(), count=%d\n", pointCount);
4882 if (!d->engine || pointCount < 2)
4886 d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
4890 d->updateState(d->state);
4892 uint emulationSpecifier = d->state->emulationSpecifier;
4894 if (emulationSpecifier) {
4895 QPainterPath polygonPath(points[0]);
4896 for (int i=1; i<pointCount; ++i)
4897 polygonPath.lineTo(points[i]);
4898 polygonPath.closeSubpath();
4899 polygonPath.setFillRule(fillRule);
4900 d->draw_helper(polygonPath);
4904 d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
4909 Draws the polygon defined by the first \a pointCount points in the
4912 void QPainter::drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule)
4914 #ifdef QT_DEBUG_DRAW
4915 if (qt_show_painter_debug_output)
4916 printf("QPainter::drawPolygon(), count=%d\n", pointCount);
4921 if (!d->engine || pointCount < 2)
4925 d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
4929 d->updateState(d->state);
4931 uint emulationSpecifier = d->state->emulationSpecifier;
4933 if (emulationSpecifier) {
4934 QPainterPath polygonPath(points[0]);
4935 for (int i=1; i<pointCount; ++i)
4936 polygonPath.lineTo(points[i]);
4937 polygonPath.closeSubpath();
4938 polygonPath.setFillRule(fillRule);
4939 d->draw_helper(polygonPath);
4943 d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule));
4946 /*! \fn void QPainter::drawPolygon(const QPolygonF &polygon, bool winding, int index = 0,
4951 Use drawPolygon() combined with QPolygonF::constData() instead.
4954 QPainter painter(this);
4955 painter.drawPolygon(polygon, winding, index, count);
4957 int pointCount = (count == -1) ? polygon.size() - index : count;
4958 int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill;
4960 QPainter painter(this);
4961 painter.drawPolygon( polygon.constData() + index, pointCount, fillRule);
4965 /*! \fn void QPainter::drawPolygon(const QPolygon &polygon, bool winding,
4966 int index = 0, int count = -1)
4971 Use drawPolygon() combined with QPolygon::constData() instead.
4974 QPainter painter(this);
4975 painter.drawPolygon(polygon, winding, index, count);
4977 int pointCount = (count == -1) ? polygon.size() - index : count;
4978 int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill;
4980 QPainter painter(this);
4981 painter.drawPolygon( polygon.constData() + index, pointCount, fillRule);
4985 /*! \fn void QPainter::drawPolygon(const QPolygonF &points, Qt::FillRule fillRule)
4989 Draws the polygon defined by the given \a points using the fill
4993 /*! \fn void QPainter::drawPolygon(const QPolygon &points, Qt::FillRule fillRule)
4997 Draws the polygon defined by the given \a points using the fill
5002 \fn void QPainter::drawConvexPolygon(const QPointF *points, int pointCount)
5004 Draws the convex polygon defined by the first \a pointCount points
5005 in the array \a points using the current pen.
5009 \o \inlineimage qpainter-polygon.png
5011 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 15
5014 The first point is implicitly connected to the last point, and the
5015 polygon is filled with the current brush(). If the supplied
5016 polygon is not convex, i.e. it contains at least one angle larger
5017 than 180 degrees, the results are undefined.
5019 On some platforms (e.g. X11), the drawConvexPolygon() function can
5020 be faster than the drawPolygon() function.
5022 \sa drawPolygon(), drawPolyline(), {Coordinate System}
5026 \fn void QPainter::drawConvexPolygon(const QPoint *points, int pointCount)
5029 Draws the convex polygon defined by the first \a pointCount points
5030 in the array \a points using the current pen.
5034 \fn void QPainter::drawConvexPolygon(const QPolygonF &polygon)
5038 Draws the convex polygon defined by \a polygon using the current
5043 \fn void QPainter::drawConvexPolygon(const QPolygon &polygon)
5046 Draws the convex polygon defined by \a polygon using the current
5051 \fn void QPainter::drawConvexPolygon(const QPolygonF &polygon, int
5057 Use drawConvexPolygon() combined with QPolygonF::constData()
5061 QPainter painter(this);
5062 painter.drawConvexPolygon(polygon, index, count);
5064 int pointCount = (count == -1) ? polygon.size() - index : count;
5066 QPainter painter(this);
5067 painter.drawConvexPolygon(polygon.constData() + index, pointCount);
5072 \fn void QPainter::drawConvexPolygon(const QPolygon &polygon, int
5078 Use drawConvexPolygon() combined with QPolygon::constData()
5082 QPainter painter(this);
5083 painter.drawConvexPolygon(polygon, index, count);
5085 int pointCount = (count == -1) ? polygon.size() - index : count;
5087 QPainter painter(this);
5088 painter.drawConvexPolygon(polygon.constData() + index, pointCount);
5092 void QPainter::drawConvexPolygon(const QPoint *points, int pointCount)
5094 #ifdef QT_DEBUG_DRAW
5095 if (qt_show_painter_debug_output)
5096 printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount);
5101 if (!d->engine || pointCount < 2)
5105 d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5109 d->updateState(d->state);
5111 uint emulationSpecifier = d->state->emulationSpecifier;
5113 if (emulationSpecifier) {
5114 QPainterPath polygonPath(points[0]);
5115 for (int i=1; i<pointCount; ++i)
5116 polygonPath.lineTo(points[i]);
5117 polygonPath.closeSubpath();
5118 polygonPath.setFillRule(Qt::WindingFill);
5119 d->draw_helper(polygonPath);
5123 d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5126 void QPainter::drawConvexPolygon(const QPointF *points, int pointCount)
5128 #ifdef QT_DEBUG_DRAW
5129 if (qt_show_painter_debug_output)
5130 printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount);
5135 if (!d->engine || pointCount < 2)
5139 d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5143 d->updateState(d->state);
5145 uint emulationSpecifier = d->state->emulationSpecifier;
5147 if (emulationSpecifier) {
5148 QPainterPath polygonPath(points[0]);
5149 for (int i=1; i<pointCount; ++i)
5150 polygonPath.lineTo(points[i]);
5151 polygonPath.closeSubpath();
5152 polygonPath.setFillRule(Qt::WindingFill);
5153 d->draw_helper(polygonPath);
5157 d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode);
5160 static inline QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m)
5162 return m.inverted().map(QPointF(m.map(p).toPoint()));
5166 \fn void QPainter::drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
5168 Draws the rectangular portion \a source of the given \a pixmap
5169 into the given \a target in the paint device.
5171 \note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
5176 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 16
5179 If \a pixmap is a QBitmap it is drawn with the bits that are "set"
5180 using the pens color. If backgroundMode is Qt::OpaqueMode, the
5181 "unset" bits are drawn using the color of the background brush; if
5182 backgroundMode is Qt::TransparentMode, the "unset" bits are
5183 transparent. Drawing bitmaps with gradient or texture colors is
5188 void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm)
5190 #if defined QT_DEBUG_DRAW
5191 if (qt_show_painter_debug_output)
5192 printf("QPainter::drawPixmap(), p=[%.2f,%.2f], pix=[%d,%d]\n",
5194 pm.width(), pm.height());
5199 if (!d->engine || pm.isNull())
5203 qt_painter_thread_test(d->device->devType(), "drawPixmap()", true);
5207 d->extended->drawPixmap(p, pm);
5215 int h = pm.height();
5220 // Emulate opaque background for bitmaps
5221 if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) {
5222 fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
5225 d->updateState(d->state);
5227 if ((d->state->matrix.type() > QTransform::TxTranslate
5228 && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5229 || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5230 || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
5233 // If there is no rotation involved we have to make sure we use the
5234 // antialiased and not the aliased coordinate system by rounding the coordinates.
5235 if (d->state->matrix.type() <= QTransform::TxScale) {
5236 const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5241 setBackgroundMode(Qt::TransparentMode);
5242 setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
5243 QBrush brush(d->state->pen.color(), pm);
5246 setBrushOrigin(QPointF(0, 0));
5248 drawRect(pm.rect());
5251 if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5252 x += d->state->matrix.dx();
5253 y += d->state->matrix.dy();
5255 d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(0, 0, w, h));
5259 void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
5261 #if defined QT_DEBUG_DRAW
5262 if (qt_show_painter_debug_output)
5263 printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n",
5264 r.x(), r.y(), r.width(), r.height(),
5265 pm.width(), pm.height(),
5266 sr.x(), sr.y(), sr.width(), sr.height());
5270 if (!d->engine || pm.isNull())
5273 qt_painter_thread_test(d->device->devType(), "drawPixmap()", true);
5278 qreal w = r.width();
5279 qreal h = r.height();
5282 qreal sw = sr.width();
5283 qreal sh = sr.height();
5285 // Sanity-check clipping
5287 sw = pm.width() - sx;
5290 sh = pm.height() - sy;
5298 qreal w_ratio = sx * w/sw;
5306 qreal h_ratio = sy * h/sh;
5313 if (sw + sx > pm.width()) {
5314 qreal delta = sw - (pm.width() - sx);
5315 qreal w_ratio = delta * w/sw;
5320 if (sh + sy > pm.height()) {
5321 qreal delta = sh - (pm.height() - sy);
5322 qreal h_ratio = delta * h/sh;
5327 if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
5331 d->extended->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
5335 // Emulate opaque background for bitmaps
5336 if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap())
5337 fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
5339 d->updateState(d->state);
5341 if ((d->state->matrix.type() > QTransform::TxTranslate
5342 && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5343 || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5344 || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))
5345 || ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform)))
5348 // If there is no rotation involved we have to make sure we use the
5349 // antialiased and not the aliased coordinate system by rounding the coordinates.
5350 if (d->state->matrix.type() <= QTransform::TxScale) {
5351 const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5356 if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) {
5364 scale(w / sw, h / sh);
5365 setBackgroundMode(Qt::TransparentMode);
5366 setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
5369 if (sw == pm.width() && sh == pm.height())
5370 brush = QBrush(d->state->pen.color(), pm);
5372 brush = QBrush(d->state->pen.color(), pm.copy(sx, sy, sw, sh));
5377 drawRect(QRectF(0, 0, sw, sh));
5380 if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5381 x += d->state->matrix.dx();
5382 y += d->state->matrix.dy();
5384 d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
5390 \fn void QPainter::drawPixmap(const QRect &target, const QPixmap &pixmap,
5391 const QRect &source)
5394 Draws the rectangular portion \a source of the given \a pixmap
5395 into the given \a target in the paint device.
5397 \note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
5401 \fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap,
5402 const QRectF &source)
5405 Draws the rectangular portion \a source of the given \a pixmap
5406 with its origin at the given \a point.
5410 \fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap,
5411 const QRect &source)
5415 Draws the rectangular portion \a source of the given \a pixmap
5416 with its origin at the given \a point.
5420 \fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap)
5423 Draws the given \a pixmap with its origin at the given \a point.
5427 \fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap)
5430 Draws the given \a pixmap with its origin at the given \a point.
5434 \fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap)
5438 Draws the given \a pixmap at position (\a{x}, \a{y}).
5442 \fn void QPainter::drawPixmap(const QRect &rectangle, const QPixmap &pixmap)
5445 Draws the given \a pixmap into the given \a rectangle.
5447 \note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
5451 \fn void QPainter::drawPixmap(int x, int y, int width, int height,
5452 const QPixmap &pixmap)
5456 Draws the \a pixmap into the rectangle at position (\a{x}, \a{y})
5457 with the given \a width and \a height.
5461 \fn void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap &pixmap,
5462 int sx, int sy, int sw, int sh)
5466 Draws the rectangular portion with the origin (\a{sx}, \a{sy}),
5467 width \a sw and height \a sh, of the given \a pixmap , at the
5468 point (\a{x}, \a{y}), with a width of \a w and a height of \a h.
5469 If sw or sh are equal to zero the width/height of the pixmap
5470 is used and adjusted by the offset sx/sy;
5474 \fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap,
5475 int sx, int sy, int sw, int sh)
5479 Draws a pixmap at (\a{x}, \a{y}) by copying a part of the given \a
5480 pixmap into the paint device.
5482 (\a{x}, \a{y}) specifies the top-left point in the paint device that is
5483 to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a
5484 pixmap that is to be drawn. The default is (0, 0).
5486 (\a{sw}, \a{sh}) specifies the size of the pixmap that is to be drawn.
5487 The default, (0, 0) (and negative) means all the way to the
5488 bottom-right of the pixmap.
5491 void QPainter::drawImage(const QPointF &p, const QImage &image)
5495 if (!d->engine || image.isNull())
5499 d->extended->drawImage(p, image);
5506 int w = image.width();
5507 int h = image.height();
5509 d->updateState(d->state);
5511 if (((d->state->matrix.type() > QTransform::TxTranslate)
5512 && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5513 || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5514 || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
5517 // If there is no rotation involved we have to make sure we use the
5518 // antialiased and not the aliased coordinate system by rounding the coordinates.
5519 if (d->state->matrix.type() <= QTransform::TxScale) {
5520 const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5525 setBackgroundMode(Qt::TransparentMode);
5526 setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
5527 QBrush brush(image);
5530 setBrushOrigin(QPointF(0, 0));
5532 drawRect(image.rect());
5537 if (d->state->matrix.type() == QTransform::TxTranslate
5538 && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5539 x += d->state->matrix.dx();
5540 y += d->state->matrix.dy();
5543 d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(0, 0, w, h), Qt::AutoColor);
5546 void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect,
5547 Qt::ImageConversionFlags flags)
5551 if (!d->engine || image.isNull())
5554 qreal x = targetRect.x();
5555 qreal y = targetRect.y();
5556 qreal w = targetRect.width();
5557 qreal h = targetRect.height();
5558 qreal sx = sourceRect.x();
5559 qreal sy = sourceRect.y();
5560 qreal sw = sourceRect.width();
5561 qreal sh = sourceRect.height();
5563 // Sanity-check clipping
5565 sw = image.width() - sx;
5568 sh = image.height() - sy;
5576 qreal w_ratio = sx * w/sw;
5584 qreal h_ratio = sy * h/sh;
5591 if (sw + sx > image.width()) {
5592 qreal delta = sw - (image.width() - sx);
5593 qreal w_ratio = delta * w/sw;
5598 if (sh + sy > image.height()) {
5599 qreal delta = sh - (image.height() - sy);
5600 qreal h_ratio = delta * h/sh;
5605 if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
5609 d->extended->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags);
5613 d->updateState(d->state);
5615 if (((d->state->matrix.type() > QTransform::TxTranslate || (sw != w || sh != h))
5616 && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
5617 || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
5618 || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
5621 // If there is no rotation involved we have to make sure we use the
5622 // antialiased and not the aliased coordinate system by rounding the coordinates.
5623 if (d->state->matrix.type() <= QTransform::TxScale) {
5624 const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix);
5629 if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) {
5636 scale(w / sw, h / sh);
5637 setBackgroundMode(Qt::TransparentMode);
5638 setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
5639 QBrush brush(image);
5642 setBrushOrigin(QPointF(-sx, -sy));
5644 drawRect(QRectF(0, 0, sw, sh));
5649 if (d->state->matrix.type() == QTransform::TxTranslate
5650 && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
5651 x += d->state->matrix.dx();
5652 y += d->state->matrix.dy();
5655 d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags);
5659 \fn void QPainter::drawGlyphRun(const QPointF &position, const QGlyphRun &glyphs)
5661 Draws the glyphs represented by \a glyphs at \a position. The \a position gives the
5662 edge of the baseline for the string of glyphs. The glyphs will be retrieved from the font
5663 selected on \a glyphs and at offsets given by the positions in \a glyphs.
5667 \sa QGlyphRun::setRawFont(), QGlyphRun::setPositions(), QGlyphRun::setGlyphIndexes()
5669 #if !defined(QT_NO_RAWFONT)
5670 void QPainter::drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun)
5674 QRawFont font = glyphRun.rawFont();
5675 if (!font.isValid())
5678 QGlyphRunPrivate *glyphRun_d = QGlyphRunPrivate::get(glyphRun);
5680 const quint32 *glyphIndexes = glyphRun_d->glyphIndexData;
5681 const QPointF *glyphPositions = glyphRun_d->glyphPositionData;
5683 int count = qMin(glyphRun_d->glyphIndexDataSize, glyphRun_d->glyphPositionDataSize);
5684 QVarLengthArray<QFixedPoint, 128> fixedPointPositions(count);
5686 QRawFontPrivate *fontD = QRawFontPrivate::get(font);
5687 bool supportsTransformations;
5688 if (d->extended != 0) {
5689 supportsTransformations = d->extended->supportsTransformations(fontD->fontEngine->fontDef.pixelSize,
5692 supportsTransformations = d->engine->type() == QPaintEngine::CoreGraphics
5693 || d->state->matrix.isAffine();
5696 for (int i=0; i<count; ++i) {
5697 QPointF processedPosition = position + glyphPositions[i];
5698 if (!supportsTransformations)
5699 processedPosition = d->state->transform().map(processedPosition);
5700 fixedPointPositions[i] = QFixedPoint::fromPointF(processedPosition);
5703 d->drawGlyphs(glyphIndexes, fixedPointPositions.data(), count, font, glyphRun.overline(),
5704 glyphRun.underline(), glyphRun.strikeOut());
5707 void QPainterPrivate::drawGlyphs(const quint32 *glyphArray, QFixedPoint *positions,
5709 const QRawFont &font, bool overline, bool underline,
5716 QRawFontPrivate *fontD = QRawFontPrivate::get(font);
5717 QFontEngine *fontEngine = fontD->fontEngine;
5722 for (int i=0; i<glyphCount; ++i) {
5723 glyph_metrics_t gm = fontEngine->boundingBox(glyphArray[i]);
5724 if (i == 0 || leftMost > positions[i].x)
5725 leftMost = positions[i].x;
5727 // We don't support glyphs that do not share a common baseline. If this turns out to
5728 // be a relevant use case, then we need to find clusters of glyphs that share a baseline
5729 // and do a drawTextItemDecorations call per cluster.
5730 if (i == 0 || baseLine < positions[i].y)
5731 baseLine = positions[i].y;
5733 // We use the advance rather than the actual bounds to match the algorithm in drawText()
5734 if (i == 0 || rightMost < positions[i].x + gm.xoff)
5735 rightMost = positions[i].x + gm.xoff;
5738 QFixed width = rightMost - leftMost;
5740 if (extended != 0 && state->matrix.isAffine()) {
5741 QStaticTextItem staticTextItem;
5742 staticTextItem.color = state->pen.color();
5743 staticTextItem.font = state->font;
5744 staticTextItem.setFontEngine(fontEngine);
5745 staticTextItem.numGlyphs = glyphCount;
5746 staticTextItem.glyphs = reinterpret_cast<glyph_t *>(const_cast<glyph_t *>(glyphArray));
5747 staticTextItem.glyphPositions = positions;
5749 extended->drawStaticTextItem(&staticTextItem);
5751 QTextItemInt textItem;
5752 textItem.fontEngine = fontEngine;
5754 QVarLengthArray<QFixed, 128> advances(glyphCount);
5755 QVarLengthArray<QGlyphJustification, 128> glyphJustifications(glyphCount);
5756 QVarLengthArray<HB_GlyphAttributes, 128> glyphAttributes(glyphCount);
5757 qMemSet(glyphAttributes.data(), 0, glyphAttributes.size() * sizeof(HB_GlyphAttributes));
5758 qMemSet(advances.data(), 0, advances.size() * sizeof(QFixed));
5759 qMemSet(glyphJustifications.data(), 0, glyphJustifications.size() * sizeof(QGlyphJustification));
5761 textItem.glyphs.numGlyphs = glyphCount;
5762 textItem.glyphs.glyphs = reinterpret_cast<HB_Glyph *>(const_cast<quint32 *>(glyphArray));
5763 textItem.glyphs.offsets = positions;
5764 textItem.glyphs.advances_x = advances.data();
5765 textItem.glyphs.advances_y = advances.data();
5766 textItem.glyphs.justifications = glyphJustifications.data();
5767 textItem.glyphs.attributes = glyphAttributes.data();
5769 engine->drawTextItem(QPointF(0, 0), textItem);
5772 QTextItemInt::RenderFlags flags;
5774 flags |= QTextItemInt::Underline;
5776 flags |= QTextItemInt::Overline;
5778 flags |= QTextItemInt::StrikeOut;
5780 drawTextItemDecoration(q, QPointF(leftMost.toReal(), baseLine.toReal()),
5783 ? QTextCharFormat::SingleUnderline
5784 : QTextCharFormat::NoUnderline),
5785 flags, width.toReal(), QTextCharFormat());
5787 #endif // QT_NO_RAWFONT
5791 \fn void QPainter::drawStaticText(const QPoint &topLeftPosition, const QStaticText &staticText)
5795 Draws the \a staticText at the \a topLeftPosition.
5797 \note The y-position is used as the top of the font.
5802 \fn void QPainter::drawStaticText(int left, int top, const QStaticText &staticText)
5806 Draws the \a staticText at coordinates \a left and \a top.
5808 \note The y-position is used as the top of the font.
5812 \fn void QPainter::drawText(const QPointF &position, const QString &text)
5814 Draws the given \a text with the currently defined text direction,
5815 beginning at the given \a position.
5817 This function does not handle the newline character (\n), as it cannot
5818 break text into multiple lines, and it cannot display the newline character.
5819 Use the QPainter::drawText() overload that takes a rectangle instead
5820 if you want to draw multiple lines of text with the newline character, or
5821 if you want the text to be wrapped.
5823 By default, QPainter draws text anti-aliased.
5825 \note The y-position is used as the baseline of the font.
5828 void QPainter::drawText(const QPointF &p, const QString &str)
5830 drawText(p, str, 0, 0);
5836 Draws the given \a staticText at the given \a topLeftPosition.
5838 The text will be drawn using the font and the transformation set on the painter. If the
5839 font and/or transformation set on the painter are different from the ones used to initialize
5840 the layout of the QStaticText, then the layout will have to be recalculated. Use
5841 QStaticText::prepare() to initialize \a staticText with the font and transformation with which
5842 it will later be drawn.
5844 If \a topLeftPosition is not the same as when \a staticText was initialized, or when it was
5845 last drawn, then there will be a slight overhead when translating the text to its new position.
5847 \note If the painter's transformation is not affine, then \a staticText will be drawn using
5848 regular calls to drawText(), losing any potential for performance improvement.
5850 \note The y-position is used as the top of the font.
5854 void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText)
5857 if (!d->engine || staticText.text().isEmpty() || pen().style() == Qt::NoPen)
5860 QStaticTextPrivate *staticText_d =
5861 const_cast<QStaticTextPrivate *>(QStaticTextPrivate::get(&staticText));
5863 if (font() != staticText_d->font) {
5864 staticText_d->font = font();
5865 staticText_d->needsRelayout = true;
5868 // If we don't have an extended paint engine, or if the painter is projected,
5869 // we go through standard code path
5870 if (d->extended == 0 || !d->state->matrix.isAffine()) {
5871 staticText_d->paintText(topLeftPosition, this);
5875 bool supportsTransformations = d->extended->supportsTransformations(staticText_d->font.pixelSize(),
5877 if (supportsTransformations && !staticText_d->untransformedCoordinates) {
5878 staticText_d->untransformedCoordinates = true;
5879 staticText_d->needsRelayout = true;
5880 } else if (!supportsTransformations && staticText_d->untransformedCoordinates) {
5881 staticText_d->untransformedCoordinates = false;
5882 staticText_d->needsRelayout = true;
5885 // Don't recalculate entire layout because of translation, rather add the dx and dy
5886 // into the position to move each text item the correct distance.
5887 QPointF transformedPosition = topLeftPosition;
5888 if (!staticText_d->untransformedCoordinates)
5889 transformedPosition = transformedPosition * d->state->matrix;
5890 QTransform oldMatrix;
5892 // The translation has been applied to transformedPosition. Remove translation
5893 // component from matrix.
5894 if (d->state->matrix.isTranslating() && !staticText_d->untransformedCoordinates) {
5895 qreal m11 = d->state->matrix.m11();
5896 qreal m12 = d->state->matrix.m12();
5897 qreal m13 = d->state->matrix.m13();
5898 qreal m21 = d->state->matrix.m21();
5899 qreal m22 = d->state->matrix.m22();
5900 qreal m23 = d->state->matrix.m23();
5901 qreal m33 = d->state->matrix.m33();
5903 oldMatrix = d->state->matrix;
5904 d->state->matrix.setMatrix(m11, m12, m13,
5909 // If the transform is not identical to the text transform,
5910 // we have to relayout the text (for other transformations than plain translation)
5911 bool staticTextNeedsReinit = staticText_d->needsRelayout;
5912 if (!staticText_d->untransformedCoordinates && staticText_d->matrix != d->state->matrix) {
5913 staticText_d->matrix = d->state->matrix;
5914 staticTextNeedsReinit = true;
5917 // Recreate the layout of the static text because the matrix or font has changed
5918 if (staticTextNeedsReinit)
5919 staticText_d->init();
5921 if (transformedPosition != staticText_d->position) { // Translate to actual position
5922 QFixed fx = QFixed::fromReal(transformedPosition.x());
5923 QFixed fy = QFixed::fromReal(transformedPosition.y());
5924 QFixed oldX = QFixed::fromReal(staticText_d->position.x());
5925 QFixed oldY = QFixed::fromReal(staticText_d->position.y());
5926 for (int item=0; item<staticText_d->itemCount;++item) {
5927 QStaticTextItem *textItem = staticText_d->items + item;
5928 for (int i=0; i<textItem->numGlyphs; ++i) {
5929 textItem->glyphPositions[i].x += fx - oldX;
5930 textItem->glyphPositions[i].y += fy - oldY;
5932 textItem->userDataNeedsUpdate = true;
5935 staticText_d->position = transformedPosition;
5938 QPen oldPen = d->state->pen;
5939 QColor currentColor = oldPen.color();
5940 for (int i=0; i<staticText_d->itemCount; ++i) {
5941 QStaticTextItem *item = staticText_d->items + i;
5942 if (item->color.isValid() && currentColor != item->color) {
5943 setPen(item->color);
5944 currentColor = item->color;
5946 d->extended->drawStaticTextItem(item);
5948 qt_draw_decoration_for_glyphs(this, item->glyphs, item->glyphPositions,
5949 item->numGlyphs, item->fontEngine(), staticText_d->font,
5952 if (currentColor != oldPen.color())
5955 if (!staticText_d->untransformedCoordinates && oldMatrix.isTranslating())
5956 d->state->matrix = oldMatrix;
5962 void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding)
5964 #ifdef QT_DEBUG_DRAW
5965 if (qt_show_painter_debug_output)
5966 printf("QPainter::drawText(), pos=[%.2f,%.2f], str='%s'\n", p.x(), p.y(), str.toLatin1().constData());
5971 if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen)
5974 if (tf & Qt::TextBypassShaping) {
5975 // Skip harfbuzz complex shaping, shape using glyph advances only
5976 int len = str.length();
5977 int numGlyphs = len;
5978 QVarLengthGlyphLayoutArray glyphs(len);
5979 QFontEngine *fontEngine = d->state->font.d->engineForScript(QUnicodeTables::Common);
5980 if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0)) {
5981 glyphs.resize(numGlyphs);
5982 if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0))
5983 Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
5986 QTextItemInt gf(glyphs, &d->state->font, str.data(), len, fontEngine);
5987 drawTextItem(p, gf);
5991 QStackTextEngine engine(str, d->state->font);
5992 engine.option.setTextDirection(d->state->layoutDirection);
5993 if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) {
5994 engine.ignoreBidi = true;
5995 engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft);
5999 line.length = str.length();
6000 engine.shapeLine(line);
6002 int nItems = engine.layoutData->items.size();
6003 QVarLengthArray<int> visualOrder(nItems);
6004 QVarLengthArray<uchar> levels(nItems);
6005 for (int i = 0; i < nItems; ++i)
6006 levels[i] = engine.layoutData->items[i].analysis.bidiLevel;
6007 QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
6009 if (justificationPadding > 0) {
6010 engine.option.setAlignment(Qt::AlignJustify);
6011 engine.forceJustification = true;
6012 // this works because justify() is only interested in the difference between width and textWidth
6013 line.width = justificationPadding;
6014 engine.justify(line);
6016 QFixed x = QFixed::fromReal(p.x());
6018 for (int i = 0; i < nItems; ++i) {
6019 int item = visualOrder[i];
6020 const QScriptItem &si = engine.layoutData->items.at(item);
6021 if (si.analysis.flags >= QScriptAnalysis::TabOrObject) {
6025 QFont f = engine.font(si);
6026 QTextItemInt gf(si, &f);
6027 gf.glyphs = engine.shapedGlyphs(&si);
6028 gf.chars = engine.layoutData->string.unicode() + si.position;
6029 gf.num_chars = engine.length(item);
6030 if (engine.forceJustification) {
6031 for (int j=0; j<gf.glyphs.numGlyphs; ++j)
6032 gf.width += gf.glyphs.effectiveAdvance(j);
6034 gf.width = si.width;
6036 gf.logClusters = engine.logClusters(&si);
6038 drawTextItem(QPointF(x.toReal(), p.y()), gf);
6044 void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br)
6046 #ifdef QT_DEBUG_DRAW
6047 if (qt_show_painter_debug_output)
6048 printf("QPainter::drawText(), r=[%d,%d,%d,%d], flags=%d, str='%s'\n",
6049 r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData());
6054 if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen)
6058 d->updateState(d->state);
6061 qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : 0, 0, 0, 0, this);
6063 *br = bounds.toAlignedRect();
6067 \fn void QPainter::drawText(const QPoint &position, const QString &text)
6071 Draws the given \a text with the currently defined text direction,
6072 beginning at the given \a position.
6074 By default, QPainter draws text anti-aliased.
6076 \note The y-position is used as the baseline of the font.
6081 \fn void QPainter::drawText(const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect)
6084 Draws the given \a text within the provided \a rectangle.
6088 \o \inlineimage qpainter-text.png
6090 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 17
6093 The \a boundingRect (if not null) is set to the what the bounding rectangle
6094 should be in order to enclose the whole text. The \a flags argument is a bitwise
6095 OR of the following flags:
6107 \o Qt::TextSingleLine
6108 \o Qt::TextExpandTabs
6109 \o Qt::TextShowMnemonic
6111 \o Qt::TextIncludeTrailingSpaces
6114 \sa Qt::AlignmentFlag, Qt::TextFlag, boundingRect(), layoutDirection()
6116 By default, QPainter draws text anti-aliased.
6118 \note The y-coordinate of \a rectangle is used as the top of the font.
6120 void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *br)
6122 #ifdef QT_DEBUG_DRAW
6123 if (qt_show_painter_debug_output)
6124 printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], flags=%d, str='%s'\n",
6125 r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData());
6130 if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen)
6134 d->updateState(d->state);
6136 qt_format_text(d->state->font, r, flags, 0, str, br, 0, 0, 0, this);
6140 \fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, QRect *boundingRect)
6143 Draws the given \a text within the provided \a rectangle according
6144 to the specified \a flags. The \a boundingRect (if not null) is set to
6145 the what the bounding rectangle should be in order to enclose the whole text.
6147 By default, QPainter draws text anti-aliased.
6149 \note The y-coordinate of \a rectangle is used as the top of the font.
6153 \fn void QPainter::drawText(int x, int y, const QString &text)
6157 Draws the given \a text at position (\a{x}, \a{y}), using the painter's
6158 currently defined text direction.
6160 By default, QPainter draws text anti-aliased.
6162 \note The y-position is used as the baseline of the font.
6167 \fn void QPainter::drawText(int x, int y, int width, int height, int flags,
6168 const QString &text, QRect *boundingRect)
6172 Draws the given \a text within the rectangle with origin (\a{x},
6173 \a{y}), \a width and \a height.
6175 The \a boundingRect (if not null) is set to the actual bounding
6176 rectangle of the output. The \a flags argument is a bitwise OR of
6177 the following flags:
6188 \o Qt::TextSingleLine
6189 \o Qt::TextExpandTabs
6190 \o Qt::TextShowMnemonic
6194 By default, QPainter draws text anti-aliased.
6196 \note The y-position is used as the top of the font.
6198 \sa Qt::AlignmentFlag, Qt::TextFlag
6202 \fn void QPainter::drawText(const QRectF &rectangle, const QString &text,
6203 const QTextOption &option)
6206 Draws the given \a text in the \a rectangle specified using the \a option
6207 to control its positioning and orientation.
6209 By default, QPainter draws text anti-aliased.
6211 \note The y-coordinate of \a rectangle is used as the top of the font.
6213 void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption &o)
6215 #ifdef QT_DEBUG_DRAW
6216 if (qt_show_painter_debug_output)
6217 printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], str='%s'\n",
6218 r.x(), r.y(), r.width(), r.height(), text.toLatin1().constData());
6223 if (!d->engine || text.length() == 0 || pen().style() == Qt::NoPen)
6227 d->updateState(d->state);
6229 qt_format_text(d->state->font, r, 0, &o, text, 0, 0, 0, 0, this);
6233 \fn void QPainter::drawTextItem(int x, int y, const QTextItem &ti)
6240 \fn void QPainter::drawTextItem(const QPoint &p, const QTextItem &ti)
6245 Draws the text item \a ti at position \a p.
6249 \fn void QPainter::drawTextItem(const QPointF &p, const QTextItem &ti)
6254 Draws the text item \a ti at position \a p.
6256 This method ignores the painters background mode and
6257 color. drawText and qt_format_text have to do it themselves, as
6258 only they know the extents of the complete string.
6260 It ignores the font set on the painter as the text item has one of its own.
6262 The underline and strikeout parameters of the text items font are
6263 ignored aswell. You'll need to pass in the correct flags to get
6264 underlining and strikeout.
6267 static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
6269 const qreal radiusBase = qMax(qreal(1), maxRadius);
6271 QString key = QLatin1Literal("WaveUnderline-")
6272 % pen.color().name()
6273 % HexString<qreal>(radiusBase);
6276 if (QPixmapCache::find(key, pixmap))
6279 const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio
6280 const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod);
6281 const int radius = qFloor(radiusBase);
6288 while (xs < width) {
6291 path.quadTo(xs - halfPeriod / 2, ys, xs, 0);
6294 pixmap = QPixmap(width, radius * 2);
6295 pixmap.fill(Qt::transparent);
6298 wavePen.setCapStyle(Qt::SquareCap);
6300 // This is to protect against making the line too fat, as happens on Mac OS X
6301 // due to it having a rather thick width for the regular underline.
6302 const qreal maxPenWidth = .8 * radius;
6303 if (wavePen.widthF() > maxPenWidth)
6304 wavePen.setWidth(maxPenWidth);
6306 QPainter imgPainter(&pixmap);
6307 imgPainter.setPen(wavePen);
6308 imgPainter.setRenderHint(QPainter::Antialiasing);
6309 imgPainter.translate(0, radius);
6310 imgPainter.drawPath(path);
6313 QPixmapCache::insert(key, pixmap);
6318 static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QFontEngine *fe,
6319 QTextCharFormat::UnderlineStyle underlineStyle,
6320 QTextItem::RenderFlags flags, qreal width,
6321 const QTextCharFormat &charFormat)
6323 if (underlineStyle == QTextCharFormat::NoUnderline
6324 && !(flags & (QTextItem::StrikeOut | QTextItem::Overline)))
6327 const QPen oldPen = painter->pen();
6328 const QBrush oldBrush = painter->brush();
6329 painter->setBrush(Qt::NoBrush);
6331 pen.setStyle(Qt::SolidLine);
6332 pen.setWidthF(fe->lineThickness().toReal());
6333 pen.setCapStyle(Qt::FlatCap);
6335 QLineF line(pos.x(), pos.y(), pos.x() + qFloor(width), pos.y());
6337 const qreal underlineOffset = fe->underlinePosition().toReal();
6338 // deliberately ceil the offset to avoid the underline coming too close to
6339 // the text above it.
6340 const qreal aliasedCoordinateDelta = 0.5 - 0.015625;
6341 const qreal underlinePos = pos.y() + qCeil(underlineOffset) - aliasedCoordinateDelta;
6343 if (underlineStyle == QTextCharFormat::SpellCheckUnderline) {
6344 underlineStyle = QTextCharFormat::SpellCheckUnderline; // ### Qt5 QTextCharFormat::UnderlineStyle(QApplication::style()->styleHint(QStyle::SH_SpellCheckUnderlineStyle));
6347 if (underlineStyle == QTextCharFormat::WaveUnderline) {
6349 painter->translate(0, pos.y() + 1);
6351 QColor uc = charFormat.underlineColor();
6355 // Adapt wave to underlineOffset or pen width, whatever is larger, to make it work on all platforms
6356 const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen);
6357 const int descent = (int) fe->descent().toReal();
6359 painter->setBrushOrigin(painter->brushOrigin().x(), 0);
6360 painter->fillRect(pos.x(), 0, qCeil(width), qMin(wave.height(), descent), wave);
6362 } else if (underlineStyle != QTextCharFormat::NoUnderline) {
6363 QLineF underLine(line.x1(), underlinePos, line.x2(), underlinePos);
6365 QColor uc = charFormat.underlineColor();
6369 pen.setStyle((Qt::PenStyle)(underlineStyle));
6370 painter->setPen(pen);
6371 painter->drawLine(underLine);
6374 pen.setStyle(Qt::SolidLine);
6375 pen.setColor(oldPen.color());
6377 if (flags & QTextItem::StrikeOut) {
6378 QLineF strikeOutLine = line;
6379 strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
6380 painter->setPen(pen);
6381 painter->drawLine(strikeOutLine);
6384 if (flags & QTextItem::Overline) {
6385 QLineF overLine = line;
6386 overLine.translate(0., - fe->ascent().toReal());
6387 painter->setPen(pen);
6388 painter->drawLine(overLine);
6391 painter->setPen(oldPen);
6392 painter->setBrush(oldBrush);
6395 Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray,
6396 const QFixedPoint *positions, int glyphCount,
6397 QFontEngine *fontEngine, const QFont &font,
6398 const QTextCharFormat &charFormat)
6400 if (!(font.underline() || font.strikeOut() || font.overline()))
6406 for (int i=0; i<glyphCount; ++i) {
6407 glyph_metrics_t gm = fontEngine->boundingBox(glyphArray[i]);
6408 if (i == 0 || leftMost > positions[i].x)
6409 leftMost = positions[i].x;
6411 // We don't support glyphs that do not share a common baseline. If this turns out to
6412 // be a relevant use case, then we need to find clusters of glyphs that share a baseline
6413 // and do a drawTextItemDecorations call per cluster.
6414 if (i == 0 || baseLine < positions[i].y)
6415 baseLine = positions[i].y;
6417 // We use the advance rather than the actual bounds to match the algorithm in drawText()
6418 if (i == 0 || rightMost < positions[i].x + gm.xoff)
6419 rightMost = positions[i].x + gm.xoff;
6422 QFixed width = rightMost - leftMost;
6423 QTextItem::RenderFlags flags = 0;
6425 if (font.underline())
6426 flags |= QTextItem::Underline;
6427 if (font.overline())
6428 flags |= QTextItem::Overline;
6429 if (font.strikeOut())
6430 flags |= QTextItem::StrikeOut;
6432 drawTextItemDecoration(painter, QPointF(leftMost.toReal(), baseLine.toReal()),
6434 font.underline() ? QTextCharFormat::SingleUnderline
6435 : QTextCharFormat::NoUnderline, flags,
6436 width.toReal(), charFormat);
6439 void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti)
6441 #ifdef QT_DEBUG_DRAW
6442 if (qt_show_painter_debug_output)
6443 printf("QPainter::drawTextItem(), pos=[%.f,%.f], str='%s'\n",
6444 p.x(), p.y(), qPrintable(_ti.text()));
6453 qt_painter_thread_test(d->device->devType(),
6455 QFontDatabase::supportsThreadedFontRendering());
6458 QTextItemInt &ti = const_cast<QTextItemInt &>(static_cast<const QTextItemInt &>(_ti));
6460 if (!d->extended && d->state->bgMode == Qt::OpaqueMode) {
6461 QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
6462 fillRect(rect, d->state->bgBrush);
6465 if (pen().style() == Qt::NoPen)
6468 const RenderHints oldRenderHints = d->state->renderHints;
6469 if (!d->state->renderHints & QPainter::Antialiasing && d->state->matrix.type() >= QTransform::TxScale) {
6470 // draw antialias decoration (underline/overline/strikeout) with
6474 const QTransform &m = d->state->matrix;
6475 if (d->state->matrix.type() < QTransform::TxShear) {
6476 bool isPlain90DegreeRotation =
6477 (qFuzzyIsNull(m.m11())
6478 && qFuzzyIsNull(m.m12() - qreal(1))
6479 && qFuzzyIsNull(m.m21() + qreal(1))
6480 && qFuzzyIsNull(m.m22())
6483 (qFuzzyIsNull(m.m11() + qreal(1))
6484 && qFuzzyIsNull(m.m12())
6485 && qFuzzyIsNull(m.m21())
6486 && qFuzzyIsNull(m.m22() + qreal(1))
6489 (qFuzzyIsNull(m.m11())
6490 && qFuzzyIsNull(m.m12() + qreal(1))
6491 && qFuzzyIsNull(m.m21() - qreal(1))
6492 && qFuzzyIsNull(m.m22())
6495 aa = !isPlain90DegreeRotation;
6498 setRenderHint(QPainter::Antialiasing, true);
6502 d->updateState(d->state);
6504 if (!ti.glyphs.numGlyphs) {
6506 } else if (ti.fontEngine->type() == QFontEngine::Multi) {
6507 QFontEngineMulti *multi = static_cast<QFontEngineMulti *>(ti.fontEngine);
6509 const QGlyphLayout &glyphs = ti.glyphs;
6510 int which = glyphs.glyphs[0] >> 24;
6515 bool rtl = ti.flags & QTextItem::RightToLeft;
6517 x += ti.width.toReal();
6521 for (end = 0; end < ti.glyphs.numGlyphs; ++end) {
6522 const int e = glyphs.glyphs[end] >> 24;
6527 QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start);
6529 // set the high byte to zero and calc the width
6530 for (i = start; i < end; ++i) {
6531 glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff;
6532 ti2.width += ti.glyphs.effectiveAdvance(i);
6536 x -= ti2.width.toReal();
6538 d->engine->drawTextItem(QPointF(x, y), ti2);
6541 x += ti2.width.toReal();
6543 // reset the high byte for all glyphs and advance to the next sub-string
6544 const int hi = which << 24;
6545 for (i = start; i < end; ++i) {
6546 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
6554 QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start);
6556 // set the high byte to zero and calc the width
6557 for (i = start; i < end; ++i) {
6558 glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff;
6559 ti2.width += ti.glyphs.effectiveAdvance(i);
6563 x -= ti2.width.toReal();
6566 d->extended->drawTextItem(QPointF(x, y), ti2);
6568 d->engine->drawTextItem(QPointF(x,y), ti2);
6570 // reset the high byte for all glyphs
6571 const int hi = which << 24;
6572 for (i = start; i < end; ++i)
6573 glyphs.glyphs[i] = hi | glyphs.glyphs[i];
6577 d->extended->drawTextItem(p, ti);
6579 d->engine->drawTextItem(p, ti);
6581 drawTextItemDecoration(this, p, ti.fontEngine, ti.underlineStyle, ti.flags, ti.width.toReal(),
6584 if (d->state->renderHints != oldRenderHints) {
6585 d->state->renderHints = oldRenderHints;
6587 d->extended->renderHintsChanged();
6589 d->state->dirtyFlags |= QPaintEngine::DirtyHints;
6594 \fn QRectF QPainter::boundingRect(const QRectF &rectangle, int flags, const QString &text)
6596 Returns the bounding rectangle of the \a text as it will appear
6597 when drawn inside the given \a rectangle with the specified \a
6598 flags using the currently set font(); i.e the function tells you
6599 where the drawText() function will draw when given the same
6602 If the \a text does not fit within the given \a rectangle using
6603 the specified \a flags, the function returns the required
6606 The \a flags argument is a bitwise OR of the following flags:
6615 \o Qt::TextSingleLine
6616 \o Qt::TextExpandTabs
6617 \o Qt::TextShowMnemonic
6619 \o Qt::TextIncludeTrailingSpaces
6621 If several of the horizontal or several of the vertical alignment
6622 flags are set, the resulting alignment is undefined.
6624 \sa drawText(), Qt::Alignment, Qt::TextFlag
6628 \fn QRect QPainter::boundingRect(const QRect &rectangle, int flags,
6629 const QString &text)
6633 Returns the bounding rectangle of the \a text as it will appear
6634 when drawn inside the given \a rectangle with the specified \a
6635 flags using the currently set font().
6639 \fn QRect QPainter::boundingRect(int x, int y, int w, int h, int flags,
6640 const QString &text);
6644 Returns the bounding rectangle of the given \a text as it will
6645 appear when drawn inside the rectangle beginning at the point
6646 (\a{x}, \a{y}) with width \a w and height \a h.
6648 QRect QPainter::boundingRect(const QRect &rect, int flags, const QString &str)
6651 return QRect(rect.x(),rect.y(), 0,0);
6653 drawText(rect, flags | Qt::TextDontPrint, str, &brect);
6659 QRectF QPainter::boundingRect(const QRectF &rect, int flags, const QString &str)
6662 return QRectF(rect.x(),rect.y(), 0,0);
6664 drawText(rect, flags | Qt::TextDontPrint, str, &brect);
6669 \fn QRectF QPainter::boundingRect(const QRectF &rectangle,
6670 const QString &text, const QTextOption &option)
6674 Instead of specifying flags as a bitwise OR of the
6675 Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes
6676 an \a option argument. The QTextOption class provides a
6677 description of general rich text properties.
6681 QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextOption &o)
6685 if (!d->engine || text.length() == 0)
6686 return QRectF(r.x(),r.y(), 0,0);
6689 qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, 0, 0, 0, this);
6694 \fn void QPainter::drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &position)
6696 Draws a tiled \a pixmap, inside the given \a rectangle with its
6697 origin at the given \a position.
6699 Calling drawTiledPixmap() is similar to calling drawPixmap()
6700 several times to fill (tile) an area with a pixmap, but is
6701 potentially much more efficient depending on the underlying window
6706 void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &sp)
6708 #ifdef QT_DEBUG_DRAW
6709 if (qt_show_painter_debug_output)
6710 printf("QPainter::drawTiledPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], offset=[%.2f,%.2f]\n",
6711 r.x(), r.y(), r.width(), r.height(),
6712 pixmap.width(), pixmap.height(),
6717 if (!d->engine || pixmap.isNull() || r.isEmpty())
6721 qt_painter_thread_test(d->device->devType(), "drawTiledPixmap()", true);
6724 qreal sw = pixmap.width();
6725 qreal sh = pixmap.height();
6729 sx = qRound(sw) - qRound(-sx) % qRound(sw);
6731 sx = qRound(sx) % qRound(sw);
6733 sy = qRound(sh) - -qRound(sy) % qRound(sh);
6735 sy = qRound(sy) % qRound(sh);
6739 d->extended->drawTiledPixmap(r, pixmap, QPointF(sx, sy));
6743 if (d->state->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
6744 fillRect(r, d->state->bgBrush);
6746 d->updateState(d->state);
6747 if ((d->state->matrix.type() > QTransform::TxTranslate
6748 && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
6749 || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)))
6752 setBackgroundMode(Qt::TransparentMode);
6753 setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
6754 setBrush(QBrush(d->state->pen.color(), pixmap));
6757 // If there is no rotation involved we have to make sure we use the
6758 // antialiased and not the aliased coordinate system by rounding the coordinates.
6759 if (d->state->matrix.type() <= QTransform::TxScale) {
6760 const QPointF p = roundInDeviceCoordinates(r.topLeft(), d->state->matrix);
6762 if (d->state->matrix.type() <= QTransform::TxTranslate) {
6767 setBrushOrigin(QPointF(r.x()-sx, r.y()-sy));
6768 drawRect(QRectF(p, r.size()));
6770 setBrushOrigin(QPointF(r.x()-sx, r.y()-sy));
6779 if (d->state->matrix.type() == QTransform::TxTranslate
6780 && !d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
6781 x += d->state->matrix.dx();
6782 y += d->state->matrix.dy();
6785 d->engine->drawTiledPixmap(QRectF(x, y, r.width(), r.height()), pixmap, QPointF(sx, sy));
6789 \fn QPainter::drawTiledPixmap(const QRect &rectangle, const QPixmap &pixmap,
6790 const QPoint &position = QPoint())
6793 Draws a tiled \a pixmap, inside the given \a rectangle with its
6794 origin at the given \a position.
6798 \fn void QPainter::drawTiledPixmap(int x, int y, int width, int height, const
6799 QPixmap &pixmap, int sx, int sy);
6802 Draws a tiled \a pixmap in the specified rectangle.
6804 (\a{x}, \a{y}) specifies the top-left point in the paint device
6805 that is to be drawn onto; with the given \a width and \a
6806 height. (\a{sx}, \a{sy}) specifies the top-left point in the \a
6807 pixmap that is to be drawn; this defaults to (0, 0).
6810 #ifndef QT_NO_PICTURE
6813 \fn void QPainter::drawPicture(const QPointF &point, const QPicture &picture)
6815 Replays the given \a picture at the given \a point.
6817 The QPicture class is a paint device that records and replays
6818 QPainter commands. A picture serializes the painter commands to an
6819 IO device in a platform-independent format. Everything that can be
6820 painted on a widget or pixmap can also be stored in a picture.
6822 This function does exactly the same as QPicture::play() when
6823 called with \a point = QPoint(0, 0).
6828 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 18
6831 \sa QPicture::play()
6834 void QPainter::drawPicture(const QPointF &p, const QPicture &picture)
6842 d->updateState(d->state);
6846 const_cast<QPicture *>(&picture)->play(this);
6851 \fn void QPainter::drawPicture(const QPoint &point, const QPicture &picture)
6854 Replays the given \a picture at the given \a point.
6858 \fn void QPainter::drawPicture(int x, int y, const QPicture &picture)
6861 Draws the given \a picture at point (\a x, \a y).
6864 #endif // QT_NO_PICTURE
6867 \fn void QPainter::eraseRect(const QRectF &rectangle)
6869 Erases the area inside the given \a rectangle. Equivalent to
6871 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 19
6875 void QPainter::eraseRect(const QRectF &r)
6879 fillRect(r, d->state->bgBrush);
6882 static inline bool needsResolving(const QBrush &brush)
6884 Qt::BrushStyle s = brush.style();
6885 return ((s == Qt::LinearGradientPattern || s == Qt::RadialGradientPattern ||
6886 s == Qt::ConicalGradientPattern) &&
6887 brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode);
6891 \fn void QPainter::eraseRect(const QRect &rectangle)
6894 Erases the area inside the given \a rectangle.
6898 \fn void QPainter::eraseRect(int x, int y, int width, int height)
6901 Erases the area inside the rectangle beginning at (\a x, \a y)
6902 with the given \a width and \a height.
6907 \fn void QPainter::fillRect(int x, int y, int width, int height, Qt::BrushStyle style)
6910 Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a
6911 width and \a height, using the brush \a style specified.
6917 \fn void QPainter::fillRect(const QRect &rectangle, Qt::BrushStyle style)
6920 Fills the given \a rectangle with the brush \a style specified.
6926 \fn void QPainter::fillRect(const QRectF &rectangle, Qt::BrushStyle style)
6929 Fills the given \a rectangle with the brush \a style specified.
6935 \fn void QPainter::fillRect(const QRectF &rectangle, const QBrush &brush)
6937 Fills the given \a rectangle with the \a brush specified.
6939 Alternatively, you can specify a QColor instead of a QBrush; the
6940 QBrush constructor (taking a QColor argument) will automatically
6941 create a solid pattern brush.
6945 void QPainter::fillRect(const QRectF &r, const QBrush &brush)
6953 const QGradient *g = brush.gradient();
6954 if (!g || g->coordinateMode() == QGradient::LogicalMode) {
6955 d->extended->fillRect(r, brush);
6960 QPen oldPen = pen();
6961 QBrush oldBrush = this->brush();
6963 if (brush.style() == Qt::SolidPattern) {
6964 d->colorBrush.setStyle(Qt::SolidPattern);
6965 d->colorBrush.setColor(brush.color());
6966 setBrush(d->colorBrush);
6977 \fn void QPainter::fillRect(const QRect &rectangle, const QBrush &brush)
6980 Fills the given \a rectangle with the specified \a brush.
6983 void QPainter::fillRect(const QRect &r, const QBrush &brush)
6991 const QGradient *g = brush.gradient();
6992 if (!g || g->coordinateMode() == QGradient::LogicalMode) {
6993 d->extended->fillRect(r, brush);
6998 QPen oldPen = pen();
6999 QBrush oldBrush = this->brush();
7001 if (brush.style() == Qt::SolidPattern) {
7002 d->colorBrush.setStyle(Qt::SolidPattern);
7003 d->colorBrush.setColor(brush.color());
7004 setBrush(d->colorBrush);
7017 \fn void QPainter::fillRect(const QRect &rectangle, const QColor &color)
7020 Fills the given \a rectangle with the \a color specified.
7024 void QPainter::fillRect(const QRect &r, const QColor &color)
7032 d->extended->fillRect(r, color);
7036 fillRect(r, QBrush(color));
7041 \fn void QPainter::fillRect(const QRectF &rectangle, const QColor &color)
7044 Fills the given \a rectangle with the \a color specified.
7048 void QPainter::fillRect(const QRectF &r, const QColor &color)
7056 d->extended->fillRect(r, color);
7060 fillRect(r, QBrush(color));
7064 \fn void QPainter::fillRect(int x, int y, int width, int height, const QBrush &brush)
7068 Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a
7069 width and \a height, using the given \a brush.
7073 \fn void QPainter::fillRect(int x, int y, int width, int height, const QColor &color)
7077 Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a
7078 width and \a height, using the given \a color.
7084 \fn void QPainter::fillRect(int x, int y, int width, int height, Qt::GlobalColor color)
7088 Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a
7089 width and \a height, using the given \a color.
7095 \fn void QPainter::fillRect(const QRect &rectangle, Qt::GlobalColor color);
7099 Fills the given \a rectangle with the specified \a color.
7105 \fn void QPainter::fillRect(const QRectF &rectangle, Qt::GlobalColor color);
7109 Fills the given \a rectangle with the specified \a color.
7115 Sets the given render \a hint on the painter if \a on is true;
7116 otherwise clears the render hint.
7118 \sa setRenderHints(), renderHints(), {QPainter#Rendering
7119 Quality}{Rendering Quality}
7121 void QPainter::setRenderHint(RenderHint hint, bool on)
7123 #ifdef QT_DEBUG_DRAW
7124 if (qt_show_painter_debug_output)
7125 printf("QPainter::setRenderHint: hint=%x, %s\n", hint, on ? "on" : "off");
7129 static const bool antialiasingDisabled = qgetenv("QT_NO_ANTIALIASING").toInt();
7130 if (hint == QPainter::Antialiasing && antialiasingDisabled)
7134 setRenderHints(hint, on);
7140 Sets the given render \a hints on the painter if \a on is true;
7141 otherwise clears the render hints.
7143 \sa setRenderHint(), renderHints(), {QPainter#Rendering
7144 Quality}{Rendering Quality}
7147 void QPainter::setRenderHints(RenderHints hints, bool on)
7152 qWarning("QPainter::setRenderHint: Painter must be active to set rendering hints");
7157 d->state->renderHints |= hints;
7159 d->state->renderHints &= ~hints;
7162 d->extended->renderHintsChanged();
7164 d->state->dirtyFlags |= QPaintEngine::DirtyHints;
7168 Returns a flag that specifies the rendering hints that are set for
7171 \sa testRenderHint(), {QPainter#Rendering Quality}{Rendering Quality}
7173 QPainter::RenderHints QPainter::renderHints() const
7175 Q_D(const QPainter);
7180 return d->state->renderHints;
7184 \fn bool QPainter::testRenderHint(RenderHint hint) const
7187 Returns true if \a hint is set; otherwise returns false.
7189 \sa renderHints(), setRenderHint()
7193 Returns true if view transformation is enabled; otherwise returns
7196 \sa setViewTransformEnabled(), worldTransform()
7199 bool QPainter::viewTransformEnabled() const
7201 Q_D(const QPainter);
7203 qWarning("QPainter::viewTransformEnabled: Painter not active");
7206 return d->state->VxF;
7210 \fn void QPainter::setWindow(const QRect &rectangle)
7212 Sets the painter's window to the given \a rectangle, and enables
7213 view transformations.
7215 The window rectangle is part of the view transformation. The
7216 window specifies the logical coordinate system. Its sister, the
7217 viewport(), specifies the device coordinate system.
7219 The default window rectangle is the same as the device's
7222 \sa window(), viewTransformEnabled(), {Coordinate
7223 System#Window-Viewport Conversion}{Window-Viewport Conversion}
7227 \fn void QPainter::setWindow(int x, int y, int width, int height)
7230 Sets the painter's window to the rectangle beginning at (\a x, \a
7231 y) and the given \a width and \a height.
7234 void QPainter::setWindow(const QRect &r)
7236 #ifdef QT_DEBUG_DRAW
7237 if (qt_show_painter_debug_output)
7238 printf("QPainter::setWindow(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
7244 qWarning("QPainter::setWindow: Painter not active");
7248 d->state->wx = r.x();
7249 d->state->wy = r.y();
7250 d->state->ww = r.width();
7251 d->state->wh = r.height();
7253 d->state->VxF = true;
7258 Returns the window rectangle.
7260 \sa setWindow(), setViewTransformEnabled()
7263 QRect QPainter::window() const
7265 Q_D(const QPainter);
7267 qWarning("QPainter::window: Painter not active");
7270 return QRect(d->state->wx, d->state->wy, d->state->ww, d->state->wh);
7274 \fn void QPainter::setViewport(const QRect &rectangle)
7276 Sets the painter's viewport rectangle to the given \a rectangle,
7277 and enables view transformations.
7279 The viewport rectangle is part of the view transformation. The
7280 viewport specifies the device coordinate system. Its sister, the
7281 window(), specifies the logical coordinate system.
7283 The default viewport rectangle is the same as the device's
7286 \sa viewport(), viewTransformEnabled() {Coordinate
7287 System#Window-Viewport Conversion}{Window-Viewport Conversion}
7291 \fn void QPainter::setViewport(int x, int y, int width, int height)
7294 Sets the painter's viewport rectangle to be the rectangle
7295 beginning at (\a x, \a y) with the given \a width and \a height.
7298 void QPainter::setViewport(const QRect &r)
7300 #ifdef QT_DEBUG_DRAW
7301 if (qt_show_painter_debug_output)
7302 printf("QPainter::setViewport(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height());
7308 qWarning("QPainter::setViewport: Painter not active");
7312 d->state->vx = r.x();
7313 d->state->vy = r.y();
7314 d->state->vw = r.width();
7315 d->state->vh = r.height();
7317 d->state->VxF = true;
7322 Returns the viewport rectangle.
7324 \sa setViewport(), setViewTransformEnabled()
7327 QRect QPainter::viewport() const
7329 Q_D(const QPainter);
7331 qWarning("QPainter::viewport: Painter not active");
7334 return QRect(d->state->vx, d->state->vy, d->state->vw, d->state->vh);
7337 /*! \fn bool QPainter::hasViewXForm() const
7340 Use viewTransformEnabled() instead.
7343 /*! \fn bool QPainter::hasWorldXForm() const
7346 Use worldMatrixEnabled() instead.
7349 /*! \fn void QPainter::resetXForm()
7352 Use resetTransform() instead.
7355 /*! \fn void QPainter::setViewXForm(bool enabled)
7358 Use setViewTransformEnabled() instead.
7361 /*! \fn void QPainter::setWorldXForm(bool enabled)
7364 Use setWorldMatrixEnabled() instead.
7367 Enables view transformations if \a enable is true, or disables
7368 view transformations if \a enable is false.
7370 \sa viewTransformEnabled(), {Coordinate System#Window-Viewport
7371 Conversion}{Window-Viewport Conversion}
7374 void QPainter::setViewTransformEnabled(bool enable)
7376 #ifdef QT_DEBUG_DRAW
7377 if (qt_show_painter_debug_output)
7378 printf("QPainter::setViewTransformEnabled(), enable=%d\n", enable);
7384 qWarning("QPainter::setViewTransformEnabled: Painter not active");
7388 if (enable == d->state->VxF)
7391 d->state->VxF = enable;
7400 Please use QWidget::render() instead.
7402 Redirects all paint commands for the given paint \a device, to the
7403 \a replacement device. The optional point \a offset defines an
7404 offset within the source device.
7406 The redirection will not be effective until the begin() function
7407 has been called; make sure to call end() for the given \a
7408 device's painter (if any) before redirecting. Call
7409 restoreRedirected() to restore the previous redirection.
7411 \warning Making use of redirections in the QPainter API implies
7412 that QPainter::begin() and QPaintDevice destructors need to hold
7413 a mutex for a short period. This can impact performance. Use of
7414 QWidget::render is strongly encouraged.
7416 \sa redirected(), restoreRedirected()
7418 void QPainter::setRedirected(const QPaintDevice *device,
7419 QPaintDevice *replacement,
7420 const QPoint &offset)
7422 Q_ASSERT(device != 0);
7423 Q_UNUSED(replacement)
7425 qWarning("QPainter::setRedirected(): ignoring call to deprecated function, use QWidget::render() instead");
7433 Using QWidget::render() obsoletes the use of this function.
7435 Restores the previous redirection for the given \a device after a
7436 call to setRedirected().
7438 \warning Making use of redirections in the QPainter API implies
7439 that QPainter::begin() and QPaintDevice destructors need to hold
7440 a mutex for a short period. This can impact performance. Use of
7441 QWidget::render is strongly encouraged.
7445 void QPainter::restoreRedirected(const QPaintDevice *device)
7448 qWarning("QPainter::restoreRedirected(): ignoring call to deprecated function, use QWidget::render() instead");
7456 Using QWidget::render() obsoletes the use of this function.
7458 Returns the replacement for given \a device. The optional out
7459 parameter \a offset returns the offset within the replaced device.
7461 \warning Making use of redirections in the QPainter API implies
7462 that QPainter::begin() and QPaintDevice destructors need to hold
7463 a mutex for a short period. This can impact performance. Use of
7464 QWidget::render is strongly encouraged.
7466 \sa setRedirected(), restoreRedirected()
7468 QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset)
7475 void qt_format_text(const QFont &fnt, const QRectF &_r,
7476 int tf, const QString& str, QRectF *brect,
7477 int tabstops, int *ta, int tabarraylen,
7480 qt_format_text(fnt, _r,
7482 tabstops, ta, tabarraylen,
7485 void qt_format_text(const QFont &fnt, const QRectF &_r,
7486 int tf, const QTextOption *option, const QString& str, QRectF *brect,
7487 int tabstops, int *ta, int tabarraylen,
7491 Q_ASSERT( !((tf & ~Qt::TextDontPrint)!=0 && option!=0) ); // we either have an option or flags
7494 tf |= option->alignment();
7495 if (option->wrapMode() != QTextOption::NoWrap)
7496 tf |= Qt::TextWordWrap;
7498 if (option->flags() & QTextOption::IncludeTrailingSpaces)
7499 tf |= Qt::TextIncludeTrailingSpaces;
7501 if (option->tabStop() >= 0 || !option->tabArray().isEmpty())
7502 tf |= Qt::TextExpandTabs;
7505 // we need to copy r here to protect against the case (&r == brect).
7508 bool dontclip = (tf & Qt::TextDontClip);
7509 bool wordwrap = (tf & Qt::TextWordWrap) || (tf & Qt::TextWrapAnywhere);
7510 bool singleline = (tf & Qt::TextSingleLine);
7511 bool showmnemonic = (tf & Qt::TextShowMnemonic);
7512 bool hidemnmemonic = (tf & Qt::TextHideMnemonic);
7514 Qt::LayoutDirection layout_direction;
7515 if (tf & Qt::TextForceLeftToRight)
7516 layout_direction = Qt::LeftToRight;
7517 else if (tf & Qt::TextForceRightToLeft)
7518 layout_direction = Qt::RightToLeft;
7520 layout_direction = option->textDirection();
7522 layout_direction = painter->layoutDirection();
7524 layout_direction = Qt::LeftToRight;
7526 tf = QGuiApplicationPrivate::visualAlignment(layout_direction, QFlag(tf));
7528 bool isRightToLeft = layout_direction == Qt::RightToLeft;
7529 bool expandtabs = ((tf & Qt::TextExpandTabs) &&
7530 (((tf & Qt::AlignLeft) && !isRightToLeft) ||
7531 ((tf & Qt::AlignRight) && isRightToLeft)));
7534 tf |= Qt::TextDontPrint;
7536 uint maxUnderlines = 0;
7537 int numUnderlines = 0;
7538 QVarLengthArray<int, 32> underlinePositions(1);
7540 QFontMetricsF fm(fnt);
7543 start_lengthVariant:
7544 bool hasMoreLengthVariants = false;
7545 // compatible behaviour to the old implementation. Replace
7547 int old_offset = offset;
7548 for (; offset < text.length(); offset++) {
7549 QChar chr = text.at(offset);
7550 if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) {
7551 text[offset] = QLatin1Char(' ');
7552 } else if (chr == QLatin1Char('\n')) {
7553 text[offset] = QChar::LineSeparator;
7554 } else if (chr == QLatin1Char('&')) {
7556 } else if (chr == QLatin1Char('\t')) {
7558 text[offset] = QLatin1Char(' ');
7559 } else if (!tabarraylen && !tabstops) {
7560 tabstops = qRound(fm.width(QLatin1Char('x'))*8);
7562 } else if (chr == QChar(ushort(0x9c))) {
7563 // string with multiple length variants
7564 hasMoreLengthVariants = true;
7569 int length = offset - old_offset;
7570 if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) {
7571 underlinePositions.resize(maxUnderlines + 1);
7573 QChar *cout = text.data() + old_offset;
7577 if (*cin == QLatin1Char('&')) {
7583 if (*cin != QLatin1Char('&') && !hidemnmemonic)
7584 underlinePositions[numUnderlines++] = cout - text.data() - old_offset;
7593 // no need to do extra work for underlines if we don't paint
7594 if (tf & Qt::TextDontPrint)
7597 underlinePositions[numUnderlines] = -1;
7601 QString finalText = text.mid(old_offset, length);
7602 QStackTextEngine engine(finalText, fnt);
7604 engine.option = *option;
7607 if (engine.option.tabStop() < 0 && tabstops > 0)
7608 engine.option.setTabStop(tabstops);
7610 if (engine.option.tabs().isEmpty() && ta) {
7612 for (int i = 0; i < tabarraylen; i++)
7613 tabs.append(qreal(ta[i]));
7614 engine.option.setTabArray(tabs);
7617 engine.option.setTextDirection(layout_direction);
7618 if (tf & Qt::AlignJustify)
7619 engine.option.setAlignment(Qt::AlignJustify);
7621 engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice
7623 if (!option && (tf & Qt::TextWrapAnywhere))
7624 engine.option.setWrapMode(QTextOption::WrapAnywhere);
7626 if (tf & Qt::TextJustificationForced)
7627 engine.forceJustification = true;
7628 QTextLayout textLayout(&engine);
7629 textLayout.setCacheEnabled(true);
7630 textLayout.engine()->underlinePositions = underlinePositions.data();
7632 if (finalText.isEmpty()) {
7633 height = fm.height();
7635 tf |= Qt::TextDontPrint;
7637 qreal lineWidth = 0x01000000;
7638 if (wordwrap || (tf & Qt::TextJustificationForced))
7639 lineWidth = qMax<qreal>(0, r.width());
7641 tf |= Qt::TextIncludeTrailingSpaces;
7642 textLayout.engine()->ignoreBidi = bool(tf & Qt::TextDontPrint);
7643 textLayout.beginLayout();
7645 qreal leading = fm.leading();
7649 QTextLine l = textLayout.createLine();
7653 l.setLineWidth(lineWidth);
7655 l.setPosition(QPointF(0., height));
7656 height += l.height();
7657 width = qMax(width, l.naturalTextWidth());
7658 if (!dontclip && !brect && height >= r.height())
7661 textLayout.endLayout();
7666 if (tf & Qt::AlignBottom) {
7667 yoff = r.height() - height;
7668 } else if (tf & Qt::AlignVCenter) {
7669 yoff = (r.height() - height)/2;
7671 QTransform::TransformationType type = painter->transform().type();
7672 if (type <= QTransform::TxScale) {
7673 // do the rounding manually to work around inconsistencies
7674 // in the paint engines when drawing on floating point offsets
7675 const qreal scale = painter->transform().m22();
7677 yoff = -qRound(-yoff * scale) / scale;
7681 if (tf & Qt::AlignRight) {
7682 xoff = r.width() - width;
7683 } else if (tf & Qt::AlignHCenter) {
7684 xoff = (r.width() - width)/2;
7686 QTransform::TransformationType type = painter->transform().type();
7687 if (type <= QTransform::TxScale) {
7688 // do the rounding manually to work around inconsistencies
7689 // in the paint engines when drawing on floating point offsets
7690 const qreal scale = painter->transform().m11();
7692 xoff = qRound(xoff * scale) / scale;
7696 QRectF bounds = QRectF(r.x() + xoff, r.y() + yoff, width, height);
7698 if (hasMoreLengthVariants && !(tf & Qt::TextLongestVariant) && !r.contains(bounds)) {
7700 goto start_lengthVariant;
7705 if (!(tf & Qt::TextDontPrint)) {
7706 bool restore = false;
7707 if (!dontclip && !r.contains(bounds)) {
7710 painter->setClipRect(r, Qt::IntersectClip);
7713 for (int i = 0; i < textLayout.lineCount(); i++) {
7714 QTextLine line = textLayout.lineAt(i);
7716 qreal advance = line.horizontalAdvance();
7718 if (tf & Qt::AlignRight) {
7719 QTextEngine *eng = textLayout.engine();
7720 xoff = r.width() - advance -
7721 eng->leadingSpaceWidth(eng->lines[line.lineNumber()]).toReal();
7723 else if (tf & Qt::AlignHCenter)
7724 xoff = (r.width() - advance) / 2;
7726 line.draw(painter, QPointF(r.x() + xoff, r.y() + yoff));
7736 Sets the layout direction used by the painter when drawing text,
7737 to the specified \a direction.
7739 The default is Qt::LayoutDirectionAuto, which will implicitly determine the
7740 direction from the text drawn.
7742 \sa QTextOption::setTextDirection(), layoutDirection(), drawText(), {QPainter#Settings}{Settings}
7744 void QPainter::setLayoutDirection(Qt::LayoutDirection direction)
7748 d->state->layoutDirection = direction;
7752 Returns the layout direction used by the painter when drawing text.
7754 \sa QTextOption::textDirection(), setLayoutDirection(), drawText(), {QPainter#Settings}{Settings}
7756 Qt::LayoutDirection QPainter::layoutDirection() const
7758 Q_D(const QPainter);
7759 return d->state ? d->state->layoutDirection : Qt::LayoutDirectionAuto;
7762 QPainterState::QPainterState(const QPainterState *s)
7763 : brushOrigin(s->brushOrigin), font(s->font), deviceFont(s->deviceFont),
7764 pen(s->pen), brush(s->brush), bgBrush(s->bgBrush),
7765 clipRegion(s->clipRegion), clipPath(s->clipPath),
7766 clipOperation(s->clipOperation),
7767 renderHints(s->renderHints), clipInfo(s->clipInfo),
7768 worldMatrix(s->worldMatrix), matrix(s->matrix), redirectionMatrix(s->redirectionMatrix),
7769 wx(s->wx), wy(s->wy), ww(s->ww), wh(s->wh),
7770 vx(s->vx), vy(s->vy), vw(s->vw), vh(s->vh),
7771 opacity(s->opacity), WxF(s->WxF), VxF(s->VxF),
7772 clipEnabled(s->clipEnabled), bgMode(s->bgMode), painter(s->painter),
7773 layoutDirection(s->layoutDirection),
7774 composition_mode(s->composition_mode),
7775 emulationSpecifier(s->emulationSpecifier), changeFlags(0)
7777 dirtyFlags = s->dirtyFlags;
7780 QPainterState::QPainterState()
7781 : brushOrigin(0, 0), bgBrush(Qt::white), clipOperation(Qt::NoClip),
7783 wx(0), wy(0), ww(0), wh(0), vx(0), vy(0), vw(0), vh(0),
7784 opacity(1), WxF(false), VxF(false), clipEnabled(true),
7785 bgMode(Qt::TransparentMode), painter(0),
7786 layoutDirection(QGuiApplication::layoutDirection()),
7787 composition_mode(QPainter::CompositionMode_SourceOver),
7788 emulationSpecifier(0), changeFlags(0)
7793 QPainterState::~QPainterState()
7797 void QPainterState::init(QPainter *p) {
7798 bgBrush = Qt::white;
7799 bgMode = Qt::TransparentMode;
7803 wx = wy = ww = wh = 0;
7804 vx = vy = vw = vh = 0;
7807 brushOrigin = QPointF(0, 0);
7809 font = deviceFont = QFont();
7810 clipRegion = QRegion();
7811 clipPath = QPainterPath();
7812 clipOperation = Qt::NoClip;
7814 worldMatrix.reset();
7816 layoutDirection = QGuiApplication::layoutDirection();
7817 composition_mode = QPainter::CompositionMode_SourceOver;
7818 emulationSpecifier = 0;
7826 \fn void QPainter::setBackgroundColor(const QColor &color)
7828 Use setBackground() instead.
7832 \fn const QColor &QPainter::backgroundColor() const
7834 Use background() and QBrush::color() instead.
7837 QColor myColor = backgroundColor();
7839 QColor myColor = background().color();
7842 Note that the background can be a complex brush such as a texture
7847 \fn void QPainter::drawText(int x, int y, const QString &text, int pos, int length)
7850 Use drawText() combined with QString::mid() instead.
7853 QPainter painter(this);
7854 painter.drawText(x, y, text, pos, length);
7856 QPainter painter(this);
7857 painter.drawText(x, y, text.mid(pos, length));
7862 \fn void QPainter::drawText(const QPoint &point, const QString &text, int pos, int length)
7865 Use drawText() combined with QString::mid() instead.
7868 QPainter painter(this);
7869 painter.drawText(point, text, pos, length);
7871 QPainter painter(this);
7872 painter.drawText(point, text.mid(pos, length));
7877 \fn void QPainter::drawText(int x, int y, const QString &text, int length)
7880 Use drawText() combined with QString::left() instead.
7883 QPainter painter(this);
7884 painter.drawText(x, y, text, length);
7886 QPainter painter(this);
7887 painter.drawText(x, y, text.left(length));
7892 \fn void QPainter::drawText(const QPoint &point, const QString &text, int length)
7895 Use drawText() combined with QString::left() instead.
7898 QPainter painter(this);
7899 painter.drawText(point, text, length);
7901 QPainter painter(this);
7902 painter.drawText(point, text.left(length));
7907 \fn bool QPainter::begin(QPaintDevice *device, const QWidget *init)
7910 Use begin() instead.
7912 If the paint \a device is a QWidget, QPainter is initialized after
7913 the widget's settings automatically. Otherwise, you must call the
7914 initFrom() function to initialize the painters pen, background and
7915 font to the same as any given widget.
7918 QPainter painter(this);
7919 painter.begin(device, init);
7921 QPainter painter(this);
7922 painter.begin(device);
7923 painter.initFrom(init);
7928 \fn void QPainter::drawImage(const QRectF &target, const QImage &image, const QRectF &source,
7929 Qt::ImageConversionFlags flags)
7931 Draws the rectangular portion \a source of the given \a image
7932 into the \a target rectangle in the paint device.
7934 \note The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
7936 If the image needs to be modified to fit in a lower-resolution
7937 result (e.g. converting from 32-bit to 8-bit), use the \a flags to
7938 specify how you would prefer this to happen.
7943 \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 20
7950 \fn void QPainter::drawImage(const QRect &target, const QImage &image, const QRect &source,
7951 Qt::ImageConversionFlags flags)
7954 Draws the rectangular portion \a source of the given \a image
7955 into the \a target rectangle in the paint device.
7957 \note The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
7961 \fn void QPainter::drawImage(const QPointF &point, const QImage &image)
7965 Draws the given \a image at the given \a point.
7969 \fn void QPainter::drawImage(const QPoint &point, const QImage &image)
7973 Draws the given \a image at the given \a point.
7977 \fn void QPainter::drawImage(const QPointF &point, const QImage &image, const QRectF &source,
7978 Qt::ImageConversionFlags flags = 0)
7982 Draws the rectangular portion \a source of the given \a image with
7983 its origin at the given \a point.
7987 \fn void QPainter::drawImage(const QPoint &point, const QImage &image, const QRect &source,
7988 Qt::ImageConversionFlags flags = 0)
7991 Draws the rectangular portion \a source of the given \a image with
7992 its origin at the given \a point.
7996 \fn void QPainter::drawImage(const QRectF &rectangle, const QImage &image)
8000 Draws the given \a image into the given \a rectangle.
8002 \note The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
8006 \fn void QPainter::drawImage(const QRect &rectangle, const QImage &image)
8010 Draws the given \a image into the given \a rectangle.
8012 \note The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
8016 \fn void QPainter::drawImage(int x, int y, const QImage &image,
8017 int sx, int sy, int sw, int sh,
8018 Qt::ImageConversionFlags flags)
8021 Draws an image at (\a{x}, \a{y}) by copying a part of \a image into
8024 (\a{x}, \a{y}) specifies the top-left point in the paint device that is
8025 to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a
8026 image that is to be drawn. The default is (0, 0).
8028 (\a{sw}, \a{sh}) specifies the size of the image that is to be drawn.
8029 The default, (0, 0) (and negative) means all the way to the
8030 bottom-right of the image.
8034 \fn void QPainter::redirect(QPaintDevice *pdev, QPaintDevice *replacement)
8036 Use setRedirected() instead.
8040 \fn QPaintDevice *QPainter::redirect(QPaintDevice *pdev)
8042 Use redirected() instead.
8046 \fn QRect QPainter::boundingRect(const QRect &rectangle, int flags,
8047 const QString &text, int length)
8050 Returns the bounding rectangle for the given \a length of the \a
8051 text constrained by the provided \a rectangle.
8053 Use boundingRect() combined with QString::left() instead.
8056 QRect rectangle = boundingRect(rect, flags, text, length);
8058 QRect rectangle = boundingRect(rect, flags, text.left(length));
8063 \fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text,
8064 int length, QRect *br)
8067 Use drawText() combined with QString::left() instead.
8070 QPainter painter(this);
8071 painter.drawText(rectangle, flags, text, length, br );
8073 QPainter painter(this);
8074 painter.drawText(rectangle, flags, text.left(length), br );
8079 \fn QRect QPainter::boundingRect(int x, int y, int width, int height, int flags,
8080 const QString &text, int length);
8084 Returns the bounding rectangle for the given \a length of the \a
8085 text constrained by the rectangle that begins at point (\a{x},
8086 \a{y}) with the given \a width and \a height.
8088 Use boundingRect() combined with QString::left() instead.
8091 QRect rectangle = boundingRect(x, y, width, height, flags, text, length);
8093 QRect rectangle = boundingRect(x, y, width, height, flags, text.left(length));
8098 \fn void QPainter::drawText(int x, int y, int width, int height, int flags,
8099 const QString &text, int length, QRect *br)
8103 Use drawText() combined with QString::left() instead.
8106 QPainter painter(this);
8107 painter.drawText(x, y, width, height, flags, text, length, br );
8109 QPainter painter(this);
8110 painter.drawText(x, y, width, height, flags, text.left(length), br );
8116 \class QPaintEngineState
8119 \brief The QPaintEngineState class provides information about the
8120 active paint engine's current state.
8123 QPaintEngineState records which properties that have changed since
8124 the last time the paint engine was updated, as well as their
8127 Which properties that have changed can at any time be retrieved
8128 using the state() function. This function returns an instance of
8129 the QPaintEngine::DirtyFlags type which stores an OR combination
8130 of QPaintEngine::DirtyFlag values. The QPaintEngine::DirtyFlag
8131 enum defines whether a property has changed since the last update
8134 If a property is marked with a dirty flag, its current value can
8135 be retrieved using the corresponding get function:
8140 \header \o Property Flag \o Current Property Value
8141 \row \o QPaintEngine::DirtyBackground \o backgroundBrush()
8142 \row \o QPaintEngine::DirtyBackgroundMode \o backgroundMode()
8143 \row \o QPaintEngine::DirtyBrush \o brush()
8144 \row \o QPaintEngine::DirtyBrushOrigin \o brushOrigin()
8145 \row \o QPaintEngine::DirtyClipRegion \e or QPaintEngine::DirtyClipPath
8147 \row \o QPaintEngine::DirtyClipPath \o clipPath()
8148 \row \o QPaintEngine::DirtyClipRegion \o clipRegion()
8149 \row \o QPaintEngine::DirtyCompositionMode \o compositionMode()
8150 \row \o QPaintEngine::DirtyFont \o font()
8151 \row \o QPaintEngine::DirtyTransform \o transform()
8152 \row \o QPaintEngine::DirtyClipEnabled \o isClipEnabled()
8153 \row \o QPaintEngine::DirtyPen \o pen()
8154 \row \o QPaintEngine::DirtyHints \o renderHints()
8157 The QPaintEngineState class also provide the painter() function
8158 which returns a pointer to the painter that is currently updating
8161 An instance of this class, representing the current state of the
8162 active paint engine, is passed as argument to the
8163 QPaintEngine::updateState() function. The only situation in which
8164 you will have to use this class directly is when implementing your
8172 \fn QPaintEngine::DirtyFlags QPaintEngineState::state() const
8174 Returns a combination of flags identifying the set of properties
8175 that need to be updated when updating the paint engine's state
8176 (i.e. during a call to the QPaintEngine::updateState() function).
8178 \sa QPaintEngine::updateState()
8183 Returns the pen in the current paint engine state.
8185 This variable should only be used when the state() returns a
8186 combination which includes the QPaintEngine::DirtyPen flag.
8188 \sa state(), QPaintEngine::updateState()
8191 QPen QPaintEngineState::pen() const
8193 return static_cast<const QPainterState *>(this)->pen;
8197 Returns the brush in the current paint engine state.
8199 This variable should only be used when the state() returns a
8200 combination which includes the QPaintEngine::DirtyBrush flag.
8202 \sa state(), QPaintEngine::updateState()
8205 QBrush QPaintEngineState::brush() const
8207 return static_cast<const QPainterState *>(this)->brush;
8211 Returns the brush origin in the current paint engine state.
8213 This variable should only be used when the state() returns a
8214 combination which includes the QPaintEngine::DirtyBrushOrigin flag.
8216 \sa state(), QPaintEngine::updateState()
8219 QPointF QPaintEngineState::brushOrigin() const
8221 return static_cast<const QPainterState *>(this)->brushOrigin;
8225 Returns the background brush in the current paint engine state.
8227 This variable should only be used when the state() returns a
8228 combination which includes the QPaintEngine::DirtyBackground flag.
8230 \sa state(), QPaintEngine::updateState()
8233 QBrush QPaintEngineState::backgroundBrush() const
8235 return static_cast<const QPainterState *>(this)->bgBrush;
8239 Returns the background mode in the current paint engine
8242 This variable should only be used when the state() returns a
8243 combination which includes the QPaintEngine::DirtyBackgroundMode flag.
8245 \sa state(), QPaintEngine::updateState()
8248 Qt::BGMode QPaintEngineState::backgroundMode() const
8250 return static_cast<const QPainterState *>(this)->bgMode;
8254 Returns the font in the current paint engine
8257 This variable should only be used when the state() returns a
8258 combination which includes the QPaintEngine::DirtyFont flag.
8260 \sa state(), QPaintEngine::updateState()
8263 QFont QPaintEngineState::font() const
8265 return static_cast<const QPainterState *>(this)->font;
8272 Returns the matrix in the current paint engine
8275 \note It is advisable to use transform() instead of this function to
8276 preserve the properties of perspective transformations.
8278 This variable should only be used when the state() returns a
8279 combination which includes the QPaintEngine::DirtyTransform flag.
8281 \sa state(), QPaintEngine::updateState()
8284 QMatrix QPaintEngineState::matrix() const
8286 const QPainterState *st = static_cast<const QPainterState *>(this);
8288 return st->matrix.toAffine();
8294 Returns the matrix in the current paint engine state.
8296 This variable should only be used when the state() returns a
8297 combination which includes the QPaintEngine::DirtyTransform flag.
8299 \sa state(), QPaintEngine::updateState()
8303 QTransform QPaintEngineState::transform() const
8305 const QPainterState *st = static_cast<const QPainterState *>(this);
8312 Returns the clip operation in the current paint engine
8315 This variable should only be used when the state() returns a
8316 combination which includes either the QPaintEngine::DirtyClipPath
8317 or the QPaintEngine::DirtyClipRegion flag.
8319 \sa state(), QPaintEngine::updateState()
8322 Qt::ClipOperation QPaintEngineState::clipOperation() const
8324 return static_cast<const QPainterState *>(this)->clipOperation;
8330 Returns whether the coordinate of the fill have been specified
8331 as bounded by the current rendering operation and have to be
8332 resolved (about the currently rendered primitive).
8334 bool QPaintEngineState::brushNeedsResolving() const
8336 const QBrush &brush = static_cast<const QPainterState *>(this)->brush;
8337 return needsResolving(brush);
8344 Returns whether the coordinate of the stroke have been specified
8345 as bounded by the current rendering operation and have to be
8346 resolved (about the currently rendered primitive).
8348 bool QPaintEngineState::penNeedsResolving() const
8350 const QPen &pen = static_cast<const QPainterState *>(this)->pen;
8351 return needsResolving(pen.brush());
8355 Returns the clip region in the current paint engine state.
8357 This variable should only be used when the state() returns a
8358 combination which includes the QPaintEngine::DirtyClipRegion flag.
8360 \sa state(), QPaintEngine::updateState()
8363 QRegion QPaintEngineState::clipRegion() const
8365 return static_cast<const QPainterState *>(this)->clipRegion;
8369 Returns the clip path in the current paint engine state.
8371 This variable should only be used when the state() returns a
8372 combination which includes the QPaintEngine::DirtyClipPath flag.
8374 \sa state(), QPaintEngine::updateState()
8377 QPainterPath QPaintEngineState::clipPath() const
8379 return static_cast<const QPainterState *>(this)->clipPath;
8383 Returns whether clipping is enabled or not in the current paint
8386 This variable should only be used when the state() returns a
8387 combination which includes the QPaintEngine::DirtyClipEnabled
8390 \sa state(), QPaintEngine::updateState()
8393 bool QPaintEngineState::isClipEnabled() const
8395 return static_cast<const QPainterState *>(this)->clipEnabled;
8399 Returns the render hints in the current paint engine state.
8401 This variable should only be used when the state() returns a
8402 combination which includes the QPaintEngine::DirtyHints
8405 \sa state(), QPaintEngine::updateState()
8408 QPainter::RenderHints QPaintEngineState::renderHints() const
8410 return static_cast<const QPainterState *>(this)->renderHints;
8414 Returns the composition mode in the current paint engine state.
8416 This variable should only be used when the state() returns a
8417 combination which includes the QPaintEngine::DirtyCompositionMode
8420 \sa state(), QPaintEngine::updateState()
8423 QPainter::CompositionMode QPaintEngineState::compositionMode() const
8425 return static_cast<const QPainterState *>(this)->composition_mode;
8430 Returns a pointer to the painter currently updating the paint
8434 QPainter *QPaintEngineState::painter() const
8436 return static_cast<const QPainterState *>(this)->painter;
8443 Returns the opacity in the current paint engine state.
8446 qreal QPaintEngineState::opacity() const
8448 return static_cast<const QPainterState *>(this)->opacity;
8454 Sets the world transformation matrix.
8455 If \a combine is true, the specified \a transform is combined with
8456 the current matrix; otherwise it replaces the current matrix.
8458 \sa transform() setWorldTransform()
8461 void QPainter::setTransform(const QTransform &transform, bool combine )
8463 setWorldTransform(transform, combine);
8467 Returns the world transformation matrix.
8469 \sa worldTransform()
8472 const QTransform & QPainter::transform() const
8474 return worldTransform();
8479 Returns the matrix that transforms from logical coordinates to
8480 device coordinates of the platform dependent paint device.
8482 This function is \e only needed when using platform painting
8483 commands on the platform dependent handle (Qt::HANDLE), and the
8484 platform does not do transformations nativly.
8486 The QPaintEngine::PaintEngineFeature enum can be queried to
8487 determine whether the platform performs the transformations or
8490 \sa worldTransform(), QPaintEngine::hasFeature(),
8493 const QTransform & QPainter::deviceTransform() const
8495 Q_D(const QPainter);
8497 qWarning("QPainter::deviceTransform: Painter not active");
8498 return d->fakeState()->transform;
8500 return d->state->matrix;
8505 Resets any transformations that were made using translate(),
8506 scale(), shear(), rotate(), setWorldTransform(), setViewport()
8509 \sa {Coordinate Transformations}
8512 void QPainter::resetTransform()
8515 #ifdef QT_DEBUG_DRAW
8516 if (qt_show_painter_debug_output)
8517 printf("QPainter::resetMatrix()\n");
8520 qWarning("QPainter::resetMatrix: Painter not active");
8524 d->state->wx = d->state->wy = d->state->vx = d->state->vy = 0; // default view origins
8525 d->state->ww = d->state->vw = d->device->metric(QPaintDevice::PdmWidth);
8526 d->state->wh = d->state->vh = d->device->metric(QPaintDevice::PdmHeight);
8527 d->state->worldMatrix = QTransform();
8528 setMatrixEnabled(false);
8529 setViewTransformEnabled(false);
8531 d->extended->transformChanged();
8533 d->state->dirtyFlags |= QPaintEngine::DirtyTransform;
8537 Sets the world transformation matrix.
8538 If \a combine is true, the specified \a matrix is combined with the current matrix;
8539 otherwise it replaces the current matrix.
8541 \sa transform(), setTransform()
8544 void QPainter::setWorldTransform(const QTransform &matrix, bool combine )
8549 qWarning("QPainter::setWorldTransform: Painter not active");
8554 d->state->worldMatrix = matrix * d->state->worldMatrix; // combines
8556 d->state->worldMatrix = matrix; // set new matrix
8558 d->state->WxF = true;
8563 Returns the world transformation matrix.
8566 const QTransform & QPainter::worldTransform() const
8568 Q_D(const QPainter);
8570 qWarning("QPainter::worldTransform: Painter not active");
8571 return d->fakeState()->transform;
8573 return d->state->worldMatrix;
8577 Returns the transformation matrix combining the current
8578 window/viewport and world transformation.
8580 \sa setWorldTransform(), setWindow(), setViewport()
8583 QTransform QPainter::combinedTransform() const
8585 Q_D(const QPainter);
8587 qWarning("QPainter::combinedTransform: Painter not active");
8588 return QTransform();
8590 return d->state->worldMatrix * d->viewTransform();
8596 This function is used to draw \a pixmap, or a sub-rectangle of \a pixmap,
8597 at multiple positions with different scale, rotation and opacity. \a
8598 fragments is an array of \a fragmentCount elements specifying the
8599 parameters used to draw each pixmap fragment. The \a hints
8600 parameter can be used to pass in drawing hints.
8602 This function is potentially faster than multiple calls to drawPixmap(),
8603 since the backend can optimize state changes.
8605 \sa QPainter::PixmapFragment, QPainter::PixmapFragmentHint
8608 void QPainter::drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount,
8609 const QPixmap &pixmap, PixmapFragmentHints hints)
8613 if (!d->engine || pixmap.isNull())
8617 for (int i = 0; i < fragmentCount; ++i) {
8618 QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
8619 fragments[i].width, fragments[i].height);
8620 if (!(QRectF(pixmap.rect()).contains(sourceRect)))
8621 qWarning("QPainter::drawPixmapFragments - the source rect is not contained by the pixmap's rectangle");
8625 if (d->engine->isExtended()) {
8626 d->extended->drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
8628 qreal oldOpacity = opacity();
8629 QTransform oldTransform = transform();
8631 for (int i = 0; i < fragmentCount; ++i) {
8632 QTransform transform = oldTransform;
8635 if (fragments[i].rotation == 0) {
8636 xOffset = fragments[i].x;
8637 yOffset = fragments[i].y;
8639 transform.translate(fragments[i].x, fragments[i].y);
8640 transform.rotate(fragments[i].rotation);
8642 setOpacity(oldOpacity * fragments[i].opacity);
8643 setTransform(transform);
8645 qreal w = fragments[i].scaleX * fragments[i].width;
8646 qreal h = fragments[i].scaleY * fragments[i].height;
8647 QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
8648 fragments[i].width, fragments[i].height);
8649 drawPixmap(QRectF(-0.5 * w + xOffset, -0.5 * h + yOffset, w, h), pixmap, sourceRect);
8652 setOpacity(oldOpacity);
8653 setTransform(oldTransform);
8659 \class QPainter::PixmapFragment
8661 \brief This class is used in conjunction with the
8662 QPainter::drawPixmapFragments() function to specify how a pixmap, or
8663 sub-rect of a pixmap, is drawn.
8665 The \a sourceLeft, \a sourceTop, \a width and \a height variables are used
8666 as a source rectangle within the pixmap passed into the
8667 QPainter::drawPixmapFragments() function. The variables \a x, \a y, \a
8668 width and \a height are used to calculate the target rectangle that is
8669 drawn. \a x and \a y denotes the center of the target rectangle. The \a
8670 width and \a height in the target rectangle is scaled by the \a scaleX and
8671 \a scaleY values. The resulting target rectangle is then rotated \a
8672 rotation degrees around the \a x, \a y center point.
8674 \sa QPainter::drawPixmapFragments()
8680 This is a convenience function that returns a QPainter::PixmapFragment that is
8681 initialized with the \a pos, \a sourceRect, \a scaleX, \a scaleY, \a
8682 rotation, \a opacity parameters.
8685 QPainter::PixmapFragment QPainter::PixmapFragment::create(const QPointF &pos, const QRectF &sourceRect,
8686 qreal scaleX, qreal scaleY, qreal rotation,
8689 PixmapFragment fragment = {pos.x(), pos.y(), sourceRect.x(), sourceRect.y(), sourceRect.width(),
8690 sourceRect.height(), scaleX, scaleY, rotation, opacity};
8695 \variable QPainter::PixmapFragment::x
8696 \brief the x coordinate of center point in the target rectangle.
8700 \variable QPainter::PixmapFragment::y
8701 \brief the y coordinate of the center point in the target rectangle.
8705 \variable QPainter::PixmapFragment::sourceLeft
8706 \brief the left coordinate of the source rectangle.
8710 \variable QPainter::PixmapFragment::sourceTop
8711 \brief the top coordinate of the source rectangle.
8715 \variable QPainter::PixmapFragment::width
8717 \brief the width of the source rectangle and is used to calculate the width
8718 of the target rectangle.
8722 \variable QPainter::PixmapFragment::height
8724 \brief the height of the source rectangle and is used to calculate the
8725 height of the target rectangle.
8729 \variable QPainter::PixmapFragment::scaleX
8730 \brief the horizontal scale of the target rectangle.
8734 \variable QPainter::PixmapFragment::scaleY
8735 \brief the vertical scale of the target rectangle.
8739 \variable QPainter::PixmapFragment::rotation
8741 \brief the rotation of the target rectangle in degrees. The target
8742 rectangle is rotated after it has been scaled.
8746 \variable QPainter::PixmapFragment::opacity
8748 \brief the opacity of the target rectangle, where 0.0 is fully transparent
8749 and 1.0 is fully opaque.
8755 \enum QPainter::PixmapFragmentHint
8757 \value OpaqueHint Indicates that the pixmap fragments to be drawn are
8758 opaque. Opaque fragments are potentially faster to draw.
8760 \sa QPainter::drawPixmapFragments(), QPainter::PixmapFragment
8763 void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
8765 p->draw_helper(path, operation);
8768 /*! \fn Display *QPaintDevice::x11Display() const
8769 Use QX11Info::display() instead.
8772 Display *display = widget->x11Display();
8774 Display *display = QX11Info::display();
8777 \sa QWidget::x11Info(), QX11Info::display()
8780 /*! \fn int QPaintDevice::x11Screen() const
8781 Use QX11Info::screen() instead.
8784 int screen = widget->x11Screen();
8786 int screen = widget->x11Info().screen();
8789 \sa QWidget::x11Info(), QPixmap::x11Info()
8792 /*! \fn void *QPaintDevice::x11Visual() const
8793 Use QX11Info::visual() instead.
8796 void *visual = widget->x11Visual();
8798 void *visual = widget->x11Info().visual();
8801 \sa QWidget::x11Info(), QPixmap::x11Info()
8804 /*! \fn int QPaintDevice::x11Depth() const
8805 Use QX11Info::depth() instead.
8808 int depth = widget->x11Depth();
8810 int depth = widget->x11Info().depth();
8813 \sa QWidget::x11Info(), QPixmap::x11Info()
8816 /*! \fn int QPaintDevice::x11Cells() const
8817 Use QX11Info::cells() instead.
8820 int cells = widget->x11Cells();
8822 int cells = widget->x11Info().cells();
8825 \sa QWidget::x11Info(), QPixmap::x11Info()
8828 /*! \fn Qt::HANDLE QPaintDevice::x11Colormap() const
8829 Use QX11Info::colormap() instead.
8832 unsigned long screen = widget->x11Colormap();
8834 unsigned long screen = widget->x11Info().colormap();
8837 \sa QWidget::x11Info(), QPixmap::x11Info()
8840 /*! \fn bool QPaintDevice::x11DefaultColormap() const
8841 Use QX11Info::defaultColormap() instead.
8844 bool isDefault = widget->x11DefaultColormap();
8846 bool isDefault = widget->x11Info().defaultColormap();
8849 \sa QWidget::x11Info(), QPixmap::x11Info()
8852 /*! \fn bool QPaintDevice::x11DefaultVisual() const
8853 Use QX11Info::defaultVisual() instead.
8856 bool isDefault = widget->x11DefaultVisual();
8858 bool isDefault = widget->x11Info().defaultVisual();
8861 \sa QWidget::x11Info(), QPixmap::x11Info()
8864 /*! \fn void *QPaintDevice::x11AppVisual(int screen)
8865 Use QX11Info::visual() instead.
8868 void *visual = QPaintDevice::x11AppVisual(screen);
8870 void *visual = qApp->x11Info(screen).visual();
8873 \sa QWidget::x11Info(), QPixmap::x11Info()
8876 /*! \fn Qt::HANDLE QPaintDevice::x11AppColormap(int screen)
8877 Use QX11Info::colormap() instead.
8880 unsigned long colormap = QPaintDevice::x11AppColormap(screen);
8882 unsigned long colormap = qApp->x11Info(screen).colormap();
8885 \sa QWidget::x11Info(), QPixmap::x11Info()
8888 /*! \fn Display *QPaintDevice::x11AppDisplay()
8889 Use QX11Info::display() instead.
8892 Display *display = QPaintDevice::x11AppDisplay();
8894 Display *display = qApp->x11Info().display();
8897 \sa QWidget::x11Info(), QPixmap::x11Info()
8900 /*! \fn int QPaintDevice::x11AppScreen()
8901 Use QX11Info::screen() instead.
8904 int screen = QPaintDevice::x11AppScreen();
8906 int screen = qApp->x11Info().screen();
8909 \sa QWidget::x11Info(), QPixmap::x11Info()
8912 /*! \fn int QPaintDevice::x11AppDepth(int screen)
8913 Use QX11Info::depth() instead.
8916 int depth = QPaintDevice::x11AppDepth(screen);
8918 int depth = qApp->x11Info(screen).depth();
8921 \sa QWidget::x11Info(), QPixmap::x11Info()
8924 /*! \fn int QPaintDevice::x11AppCells(int screen)
8925 Use QX11Info::cells() instead.
8928 int cells = QPaintDevice::x11AppCells(screen);
8930 int cells = qApp->x11Info(screen).cells();
8933 \sa QWidget::x11Info(), QPixmap::x11Info()
8936 /*! \fn Qt::HANDLE QPaintDevice::x11AppRootWindow(int screen)
8937 Use QX11Info::appRootWindow() instead.
8940 unsigned long window = QPaintDevice::x11AppRootWindow(screen);
8942 unsigned long window = qApp->x11Info(screen).appRootWindow();
8945 \sa QWidget::x11Info(), QPixmap::x11Info()
8948 /*! \fn bool QPaintDevice::x11AppDefaultColormap(int screen)
8949 Use QX11Info::defaultColormap() instead.
8952 bool isDefault = QPaintDevice::x11AppDefaultColormap(screen);
8954 bool isDefault = qApp->x11Info(screen).defaultColormap();
8957 \sa QWidget::x11Info(), QPixmap::x11Info()
8960 /*! \fn bool QPaintDevice::x11AppDefaultVisual(int screen)
8961 Use QX11Info::defaultVisual() instead.
8964 bool isDefault = QPaintDevice::x11AppDefaultVisual(screen);
8966 bool isDefault = qApp->x11Info(screen).defaultVisual();
8969 \sa QWidget::x11Info(), QPixmap::x11Info()
8972 /*! \fn void QPaintDevice::x11SetAppDpiX(int dpi, int screen)
8973 Use QX11Info::setAppDpiX() instead.
8976 /*! \fn void QPaintDevice::x11SetAppDpiY(int dpi, int screen)
8977 Use QX11Info::setAppDpiY() instead.
8980 /*! \fn int QPaintDevice::x11AppDpiX(int screen)
8981 Use QX11Info::appDpiX() instead.
8984 bool isDefault = QPaintDevice::x11AppDpiX(screen);
8986 bool isDefault = qApp->x11Info(screen).appDpiX();
8989 \sa QWidget::x11Info(), QPixmap::x11Info()
8992 /*! \fn int QPaintDevice::x11AppDpiY(int screen)
8993 Use QX11Info::appDpiY() instead.
8996 bool isDefault = QPaintDevice::x11AppDpiY(screen);
8998 bool isDefault = qApp->x11Info(screen).appDpiY();
9001 \sa QWidget::x11Info(), QPixmap::x11Info()
9004 /*! \fn HDC QPaintDevice::getDC() const
9008 /*! \fn void QPaintDevice::releaseDC(HDC) const
9012 /*! \fn QWSDisplay *QPaintDevice::qwsDisplay()