Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpainter.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QPAINTER_H
6#define QPAINTER_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qrect.h>
11#include <QtCore/qpoint.h>
12#include <QtCore/qscopedpointer.h>
13#include <QtGui/qpixmap.h>
14#include <QtGui/qimage.h>
15#include <QtGui/qtextoption.h>
16#include <memory>
17
18#ifndef QT_INCLUDE_COMPAT
19#include <QtGui/qpolygon.h>
20#include <QtGui/qpen.h>
21#include <QtGui/qbrush.h>
22#include <QtGui/qtransform.h>
23#include <QtGui/qfontinfo.h>
24#include <QtGui/qfontmetrics.h>
25#endif
26
28
29
30class QBrush;
31class QFontInfo;
32class QFontMetrics;
33class QPaintDevice;
34class QPainterPath;
35class QPainterPrivate;
36class QPen;
37class QPolygon;
38class QTextItem;
39class QTextEngine;
40class QTransform;
41class QStaticText;
42class QGlyphRun;
43
44class QPainterPrivateDeleter;
45
46class Q_GUI_EXPORT QPainter
47{
48 Q_DECLARE_PRIVATE(QPainter)
49 Q_GADGET
50
51public:
52 enum RenderHint {
53 Antialiasing = 0x01,
54 TextAntialiasing = 0x02,
55 SmoothPixmapTransform = 0x04,
56 VerticalSubpixelPositioning = 0x08,
57 LosslessImageRendering = 0x40,
58 NonCosmeticBrushPatterns = 0x80
59 };
60 Q_ENUM(RenderHint)
61
62 Q_DECLARE_FLAGS(RenderHints, RenderHint)
63 Q_FLAG(RenderHints)
64
65 class PixmapFragment {
66 public:
67 qreal x;
68 qreal y;
69 qreal sourceLeft;
70 qreal sourceTop;
71 qreal width;
72 qreal height;
73 qreal scaleX;
74 qreal scaleY;
75 qreal rotation;
76 qreal opacity;
77 static PixmapFragment Q_GUI_EXPORT create(const QPointF &pos, const QRectF &sourceRect,
78 qreal scaleX = 1, qreal scaleY = 1,
79 qreal rotation = 0, qreal opacity = 1);
80 };
81
84 };
85
86 Q_DECLARE_FLAGS(PixmapFragmentHints, PixmapFragmentHint)
87
88 QPainter();
89 explicit QPainter(QPaintDevice *);
90 ~QPainter();
91
92 QPaintDevice *device() const;
93
94 bool begin(QPaintDevice *);
95 bool end();
96 bool isActive() const;
97
146
147 const QFont &font() const;
148 void setFont(const QFont &f);
149
150 QFontMetrics fontMetrics() const;
151 QFontInfo fontInfo() const;
152
153 void setPen(const QColor &color);
154 QT_GUI_INLINE_SINCE(6, 11)
155 void setPen(const QPen &pen);
156 void setPen(QPen &&pen) { doSetPen(pen, &pen); }
157 void setPen(Qt::PenStyle style);
158 const QPen &pen() const;
159
160 QT_GUI_INLINE_SINCE(6, 11)
161 void setBrush(const QBrush &brush);
162 void setBrush(QBrush &&brush) { doSetBrush(brush, &brush); }
163 void setBrush(Qt::BrushStyle style);
164 void setBrush(QColor color);
165 void setBrush(Qt::GlobalColor color) { setBrush(QColor(color)); }
166 const QBrush &brush() const;
167
168 // attributes/modes
169 void setBackgroundMode(Qt::BGMode mode);
170 Qt::BGMode backgroundMode() const;
171
172 QPoint brushOrigin() const;
173 QPointF brushOriginF() const;
174 inline void setBrushOrigin(int x, int y);
175 inline void setBrushOrigin(const QPoint &);
176 void setBrushOrigin(const QPointF &);
177
178 void setBackground(const QBrush &bg);
179 const QBrush &background() const;
180
181 qreal opacity() const;
182 void setOpacity(qreal opacity);
183
184 // Clip functions
185 QRegion clipRegion() const;
186 QPainterPath clipPath() const;
187
188 void setClipRect(const QRectF &, Qt::ClipOperation op = Qt::ReplaceClip);
189 void setClipRect(const QRect &, Qt::ClipOperation op = Qt::ReplaceClip);
190 inline void setClipRect(int x, int y, int w, int h, Qt::ClipOperation op = Qt::ReplaceClip);
191
192 void setClipRegion(const QRegion &, Qt::ClipOperation op = Qt::ReplaceClip);
193
194 void setClipPath(const QPainterPath &path, Qt::ClipOperation op = Qt::ReplaceClip);
195
196 void setClipping(bool enable);
197 bool hasClipping() const;
198
199 QRectF clipBoundingRect() const;
200
201 void save();
202 void restore();
203
204 // XForm functions
205 void setTransform(const QTransform &transform, bool combine = false);
206 const QTransform &transform() const;
207 const QTransform &deviceTransform() const;
208 void resetTransform();
209
210 void setWorldTransform(const QTransform &matrix, bool combine = false);
211 const QTransform &worldTransform() const;
212
213 QTransform combinedTransform() const;
214
215 void setWorldMatrixEnabled(bool enabled);
216 bool worldMatrixEnabled() const;
217
218 void scale(qreal sx, qreal sy);
219 void shear(qreal sh, qreal sv);
220 void rotate(qreal a);
221
222 void translate(const QPointF &offset);
223 inline void translate(const QPoint &offset);
224 inline void translate(qreal dx, qreal dy);
225
226 QRect window() const;
227 void setWindow(const QRect &window);
228 inline void setWindow(int x, int y, int w, int h);
229
230 QRect viewport() const;
231 void setViewport(const QRect &viewport);
232 inline void setViewport(int x, int y, int w, int h);
233
234 void setViewTransformEnabled(bool enable);
235 bool viewTransformEnabled() const;
236
237 // drawing functions
238 void strokePath(const QPainterPath &path, const QPen &pen);
239 void fillPath(const QPainterPath &path, const QBrush &brush);
240 void drawPath(const QPainterPath &path);
241
242 inline void drawPoint(const QPointF &pt);
243 inline void drawPoint(const QPoint &p);
244 inline void drawPoint(int x, int y);
245
246 void drawPoints(const QPointF *points, int pointCount);
247 inline void drawPoints(const QPolygonF &points);
248 void drawPoints(const QPoint *points, int pointCount);
249 inline void drawPoints(const QPolygon &points);
250
251 inline void drawLine(const QLineF &line);
252 inline void drawLine(const QLine &line);
253 inline void drawLine(int x1, int y1, int x2, int y2);
254 inline void drawLine(const QPoint &p1, const QPoint &p2);
255 inline void drawLine(const QPointF &p1, const QPointF &p2);
256
257 void drawLines(const QLineF *lines, int lineCount);
258 inline void drawLines(const QList<QLineF> &lines);
259 void drawLines(const QPointF *pointPairs, int lineCount);
260 inline void drawLines(const QList<QPointF> &pointPairs);
261 void drawLines(const QLine *lines, int lineCount);
262 inline void drawLines(const QList<QLine> &lines);
263 void drawLines(const QPoint *pointPairs, int lineCount);
264 inline void drawLines(const QList<QPoint> &pointPairs);
265
266 inline void drawRect(const QRectF &rect);
267 inline void drawRect(int x1, int y1, int w, int h);
268 inline void drawRect(const QRect &rect);
269
270 void drawRects(const QRectF *rects, int rectCount);
271 inline void drawRects(const QList<QRectF> &rectangles);
272 void drawRects(const QRect *rects, int rectCount);
273 inline void drawRects(const QList<QRect> &rectangles);
274
275 void drawEllipse(const QRectF &r);
276 void drawEllipse(const QRect &r);
277 inline void drawEllipse(int x, int y, int w, int h);
278
279 inline void drawEllipse(const QPointF &center, qreal rx, qreal ry);
280 inline void drawEllipse(const QPoint &center, int rx, int ry);
281
282 void drawPolyline(const QPointF *points, int pointCount);
283 inline void drawPolyline(const QPolygonF &polyline);
284 void drawPolyline(const QPoint *points, int pointCount);
285 inline void drawPolyline(const QPolygon &polygon);
286
287 void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
288 inline void drawPolygon(const QPolygonF &polygon, Qt::FillRule fillRule = Qt::OddEvenFill);
289 void drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill);
290 inline void drawPolygon(const QPolygon &polygon, Qt::FillRule fillRule = Qt::OddEvenFill);
291
292 void drawConvexPolygon(const QPointF *points, int pointCount);
293 inline void drawConvexPolygon(const QPolygonF &polygon);
294 void drawConvexPolygon(const QPoint *points, int pointCount);
295 inline void drawConvexPolygon(const QPolygon &polygon);
296
297 void drawArc(const QRectF &rect, int a, int alen);
298 inline void drawArc(const QRect &, int a, int alen);
299 inline void drawArc(int x, int y, int w, int h, int a, int alen);
300
301 void drawPie(const QRectF &rect, int a, int alen);
302 inline void drawPie(int x, int y, int w, int h, int a, int alen);
303 inline void drawPie(const QRect &, int a, int alen);
304
305 void drawChord(const QRectF &rect, int a, int alen);
306 inline void drawChord(int x, int y, int w, int h, int a, int alen);
307 inline void drawChord(const QRect &, int a, int alen);
308
309 void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
310 Qt::SizeMode mode = Qt::AbsoluteSize);
311 inline void drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius,
312 Qt::SizeMode mode = Qt::AbsoluteSize);
313 inline void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius,
314 Qt::SizeMode mode = Qt::AbsoluteSize);
315
316 void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset = QPointF());
317 inline void drawTiledPixmap(int x, int y, int w, int h, const QPixmap &, int sx=0, int sy=0);
318 inline void drawTiledPixmap(const QRect &, const QPixmap &, const QPoint & = QPoint());
319#ifndef QT_NO_PICTURE
320 void drawPicture(const QPointF &p, const QPicture &picture);
321 inline void drawPicture(int x, int y, const QPicture &picture);
322 inline void drawPicture(const QPoint &p, const QPicture &picture);
323#endif
324
325 void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect);
326 inline void drawPixmap(const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect);
327 inline void drawPixmap(int x, int y, int w, int h, const QPixmap &pm,
328 int sx, int sy, int sw, int sh);
329 inline void drawPixmap(int x, int y, const QPixmap &pm,
330 int sx, int sy, int sw, int sh);
331 inline void drawPixmap(const QPointF &p, const QPixmap &pm, const QRectF &sr);
332 inline void drawPixmap(const QPoint &p, const QPixmap &pm, const QRect &sr);
333 void drawPixmap(const QPointF &p, const QPixmap &pm);
334 inline void drawPixmap(const QPoint &p, const QPixmap &pm);
335 inline void drawPixmap(int x, int y, const QPixmap &pm);
336 inline void drawPixmap(const QRect &r, const QPixmap &pm);
337 inline void drawPixmap(int x, int y, int w, int h, const QPixmap &pm);
338
339 void drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount,
340 const QPixmap &pixmap, PixmapFragmentHints hints = PixmapFragmentHints());
341
342 void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect,
343 Qt::ImageConversionFlags flags = Qt::AutoColor);
344 inline void drawImage(const QRect &targetRect, const QImage &image, const QRect &sourceRect,
345 Qt::ImageConversionFlags flags = Qt::AutoColor);
346 inline void drawImage(const QPointF &p, const QImage &image, const QRectF &sr,
347 Qt::ImageConversionFlags flags = Qt::AutoColor);
348 inline void drawImage(const QPoint &p, const QImage &image, const QRect &sr,
349 Qt::ImageConversionFlags flags = Qt::AutoColor);
350 inline void drawImage(const QRectF &r, const QImage &image);
351 inline void drawImage(const QRect &r, const QImage &image);
352 void drawImage(const QPointF &p, const QImage &image);
353 inline void drawImage(const QPoint &p, const QImage &image);
354 inline void drawImage(int x, int y, const QImage &image, int sx = 0, int sy = 0,
355 int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor);
356
357 void setLayoutDirection(Qt::LayoutDirection direction);
359
360#if !defined(QT_NO_RAWFONT)
361 void drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun);
362#endif
363
364 void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText);
365 inline void drawStaticText(const QPoint &topLeftPosition, const QStaticText &staticText);
366 inline void drawStaticText(int left, int top, const QStaticText &staticText);
367
368 void drawText(const QPointF &p, const QString &s);
369 inline void drawText(const QPoint &p, const QString &s);
370 inline void drawText(int x, int y, const QString &s);
371
372 void drawText(const QPointF &p, const QString &str, int tf, int justificationPadding);
373
374 void drawText(const QRectF &r, int flags, const QString &text, QRectF *br = nullptr);
375 void drawText(const QRect &r, int flags, const QString &text, QRect *br = nullptr);
376 inline void drawText(int x, int y, int w, int h, int flags, const QString &text, QRect *br = nullptr);
377
378 void drawText(const QRectF &r, const QString &text, const QTextOption &o = QTextOption());
379
380 QRectF boundingRect(const QRectF &rect, int flags, const QString &text);
381 QRect boundingRect(const QRect &rect, int flags, const QString &text);
382 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text);
383
384 QRectF boundingRect(const QRectF &rect, const QString &text, const QTextOption &o = QTextOption());
385
386 void drawTextItem(const QPointF &p, const QTextItem &ti);
387 inline void drawTextItem(int x, int y, const QTextItem &ti);
388 inline void drawTextItem(const QPoint &p, const QTextItem &ti);
389
390 void fillRect(const QRectF &, const QBrush &);
391 inline void fillRect(int x, int y, int w, int h, const QBrush &);
392 void fillRect(const QRect &, const QBrush &);
393
394 void fillRect(const QRectF &, const QColor &color);
395 inline void fillRect(int x, int y, int w, int h, const QColor &color);
396 void fillRect(const QRect &, const QColor &color);
397
398 inline void fillRect(int x, int y, int w, int h, Qt::GlobalColor c);
399 inline void fillRect(const QRect &r, Qt::GlobalColor c);
400 inline void fillRect(const QRectF &r, Qt::GlobalColor c);
401
402 inline void fillRect(int x, int y, int w, int h, Qt::BrushStyle style);
403 inline void fillRect(const QRect &r, Qt::BrushStyle style);
404 inline void fillRect(const QRectF &r, Qt::BrushStyle style);
405
406 inline void fillRect(int x, int y, int w, int h, QGradient::Preset preset);
407 inline void fillRect(const QRect &r, QGradient::Preset preset);
408 inline void fillRect(const QRectF &r, QGradient::Preset preset);
409
410 void eraseRect(const QRectF &);
411 inline void eraseRect(int x, int y, int w, int h);
412 inline void eraseRect(const QRect &);
413
414 void setRenderHint(RenderHint hint, bool on = true);
415 void setRenderHints(RenderHints hints, bool on = true);
416 RenderHints renderHints() const;
417 inline bool testRenderHint(RenderHint hint) const { return bool(renderHints() & hint); }
418
419 QPaintEngine *paintEngine() const;
420
421 void beginNativePainting();
422 void endNativePainting();
423
424private:
425 Q_DISABLE_COPY(QPainter)
426
427 void doSetPen(const QPen &lvalue, QPen *rvalue);
428 void doSetBrush(const QBrush &lvalue, QBrush *rvalue);
429
430 std::unique_ptr<QPainterPrivate> d_ptr;
431
432 friend class QWidget;
433 friend class QFontEngine;
434 friend class QFontEngineBox;
435 friend class QFontEngineFT;
436 friend class QFontEngineMac;
437 friend class QFontEngineWin;
438 friend class QPaintEngine;
440 friend class QOpenGLPaintEngine;
441 friend class QWin32PaintEngine;
443 friend class QRasterPaintEngine;
444 friend class QAlphaPaintEngine;
446 friend class QTextEngine;
447};
448Q_DECLARE_TYPEINFO(QPainter::PixmapFragment, Q_RELOCATABLE_TYPE);
449
450Q_DECLARE_OPERATORS_FOR_FLAGS(QPainter::RenderHints)
451
452//
453// functions
454//
455inline void QPainter::drawLine(const QLineF &l)
456{
457 drawLines(&l, 1);
458}
459
460inline void QPainter::drawLine(const QLine &line)
461{
462 drawLines(&line, 1);
463}
464
465inline void QPainter::drawLine(int x1, int y1, int x2, int y2)
466{
467 QLine l(x1, y1, x2, y2);
468 drawLines(&l, 1);
469}
470
471inline void QPainter::drawLine(const QPoint &p1, const QPoint &p2)
472{
473 QLine l(p1, p2);
474 drawLines(&l, 1);
475}
476
477inline void QPainter::drawLine(const QPointF &p1, const QPointF &p2)
478{
479 drawLine(QLineF(p1, p2));
480}
481
482inline void QPainter::drawLines(const QList<QLineF> &lines)
483{
484 drawLines(lines.constData(), int(lines.size()));
485}
486
487inline void QPainter::drawLines(const QList<QLine> &lines)
488{
489 drawLines(lines.constData(), int(lines.size()));
490}
491
492inline void QPainter::drawLines(const QList<QPointF> &pointPairs)
493{
494 drawLines(pointPairs.constData(), int(pointPairs.size() / 2));
495}
496
497inline void QPainter::drawLines(const QList<QPoint> &pointPairs)
498{
499 drawLines(pointPairs.constData(), int(pointPairs.size() / 2));
500}
501
502inline void QPainter::drawPolyline(const QPolygonF &polyline)
503{
504 drawPolyline(polyline.constData(), int(polyline.size()));
505}
506
507inline void QPainter::drawPolyline(const QPolygon &polyline)
508{
509 drawPolyline(polyline.constData(), int(polyline.size()));
510}
511
512inline void QPainter::drawPolygon(const QPolygonF &polygon, Qt::FillRule fillRule)
513{
514 drawPolygon(polygon.constData(), int(polygon.size()), fillRule);
515}
516
517inline void QPainter::drawPolygon(const QPolygon &polygon, Qt::FillRule fillRule)
518{
519 drawPolygon(polygon.constData(), int(polygon.size()), fillRule);
520}
521
522inline void QPainter::drawConvexPolygon(const QPolygonF &poly)
523{
524 drawConvexPolygon(poly.constData(), int(poly.size()));
525}
526
527inline void QPainter::drawConvexPolygon(const QPolygon &poly)
528{
529 drawConvexPolygon(poly.constData(), int(poly.size()));
530}
531
532inline void QPainter::drawRect(const QRectF &rect)
533{
534 drawRects(&rect, 1);
535}
536
537inline void QPainter::drawRect(int x, int y, int w, int h)
538{
539 QRect r(x, y, w, h);
540 drawRects(&r, 1);
541}
542
543inline void QPainter::drawRect(const QRect &r)
544{
545 drawRects(&r, 1);
546}
547
548inline void QPainter::drawRects(const QList<QRectF> &rects)
549{
550 drawRects(rects.constData(), int(rects.size()));
551}
552
553inline void QPainter::drawRects(const QList<QRect> &rects)
554{
555 drawRects(rects.constData(), int(rects.size()));
556}
557
558inline void QPainter::drawPoint(const QPointF &p)
559{
560 drawPoints(&p, 1);
561}
562
563inline void QPainter::drawPoint(int x, int y)
564{
565 QPoint p(x, y);
566 drawPoints(&p, 1);
567}
568
569inline void QPainter::drawPoint(const QPoint &p)
570{
571 drawPoints(&p, 1);
572}
573
574inline void QPainter::drawPoints(const QPolygonF &points)
575{
576 drawPoints(points.constData(), int(points.size()));
577}
578
579inline void QPainter::drawPoints(const QPolygon &points)
580{
581 drawPoints(points.constData(), int(points.size()));
582}
583
584inline void QPainter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius,
585 Qt::SizeMode mode)
586{
587 drawRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
588}
589
590inline void QPainter::drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius,
591 Qt::SizeMode mode)
592{
593 drawRoundedRect(QRectF(rect), xRadius, yRadius, mode);
594}
595
596inline void QPainter::drawEllipse(int x, int y, int w, int h)
597{
598 drawEllipse(QRect(x, y, w, h));
599}
600
601inline void QPainter::drawEllipse(const QPointF &center, qreal rx, qreal ry)
602{
603 drawEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
604}
605
606inline void QPainter::drawEllipse(const QPoint &center, int rx, int ry)
607{
608 drawEllipse(QRect(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
609}
610
611inline void QPainter::drawArc(const QRect &r, int a, int alen)
612{
613 drawArc(QRectF(r), a, alen);
614}
615
616inline void QPainter::drawArc(int x, int y, int w, int h, int a, int alen)
617{
618 drawArc(QRectF(x, y, w, h), a, alen);
619}
620
621inline void QPainter::drawPie(const QRect &rect, int a, int alen)
622{
623 drawPie(QRectF(rect), a, alen);
624}
625
626inline void QPainter::drawPie(int x, int y, int w, int h, int a, int alen)
627{
628 drawPie(QRectF(x, y, w, h), a, alen);
629}
630
631inline void QPainter::drawChord(const QRect &rect, int a, int alen)
632{
633 drawChord(QRectF(rect), a, alen);
634}
635
636inline void QPainter::drawChord(int x, int y, int w, int h, int a, int alen)
637{
638 drawChord(QRectF(x, y, w, h), a, alen);
639}
640
641inline void QPainter::setClipRect(int x, int y, int w, int h, Qt::ClipOperation op)
642{
643 setClipRect(QRect(x, y, w, h), op);
644}
645
646inline void QPainter::eraseRect(const QRect &rect)
647{
648 eraseRect(QRectF(rect));
649}
650
651inline void QPainter::eraseRect(int x, int y, int w, int h)
652{
653 eraseRect(QRectF(x, y, w, h));
654}
655
656inline void QPainter::fillRect(int x, int y, int w, int h, const QBrush &b)
657{
658 fillRect(QRect(x, y, w, h), b);
659}
660
661inline void QPainter::fillRect(int x, int y, int w, int h, const QColor &b)
662{
663 fillRect(QRect(x, y, w, h), b);
664}
665
666inline void QPainter::fillRect(int x, int y, int w, int h, Qt::GlobalColor c)
667{
668 fillRect(QRect(x, y, w, h), QColor(c));
669}
670
671inline void QPainter::fillRect(const QRect &r, Qt::GlobalColor c)
672{
673 fillRect(r, QColor(c));
674}
675
676inline void QPainter::fillRect(const QRectF &r, Qt::GlobalColor c)
677{
678 fillRect(r, QColor(c));
679}
680
681inline void QPainter::fillRect(int x, int y, int w, int h, Qt::BrushStyle style)
682{
683 fillRect(QRectF(x, y, w, h), QBrush(style));
684}
685
686inline void QPainter::fillRect(const QRect &r, Qt::BrushStyle style)
687{
688 fillRect(QRectF(r), QBrush(style));
689}
690
691inline void QPainter::fillRect(const QRectF &r, Qt::BrushStyle style)
692{
693 fillRect(r, QBrush(style));
694}
695
696inline void QPainter::fillRect(int x, int y, int w, int h, QGradient::Preset p)
697{
698 fillRect(QRect(x, y, w, h), QGradient(p));
699}
700
701inline void QPainter::fillRect(const QRect &r, QGradient::Preset p)
702{
703 fillRect(r, QGradient(p));
704}
705
706inline void QPainter::fillRect(const QRectF &r, QGradient::Preset p)
707{
708 fillRect(r, QGradient(p));
709}
710
711#if QT_GUI_INLINE_IMPL_SINCE(6, 11)
712
713void QPainter::setPen(const QPen &p)
714{
715 doSetPen(p, nullptr);
716}
717
718void QPainter::setBrush(const QBrush &b)
719{
720 doSetBrush(b, nullptr);
721}
722
723#endif // QT_GUI_INLINE_IMPL_SINCE(6, 11)
724
725
726inline void QPainter::setBrushOrigin(int x, int y)
727{
728 setBrushOrigin(QPoint(x, y));
729}
730
731inline void QPainter::setBrushOrigin(const QPoint &p)
732{
733 setBrushOrigin(QPointF(p));
734}
735
736inline void QPainter::drawTiledPixmap(const QRect &rect, const QPixmap &pm, const QPoint &offset)
737{
738 drawTiledPixmap(QRectF(rect), pm, QPointF(offset));
739}
740
741inline void QPainter::drawTiledPixmap(int x, int y, int w, int h, const QPixmap &pm, int sx, int sy)
742{
743 drawTiledPixmap(QRectF(x, y, w, h), pm, QPointF(sx, sy));
744}
745
746inline void QPainter::drawPixmap(const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect)
747{
748 drawPixmap(QRectF(targetRect), pixmap, QRectF(sourceRect));
749}
750
751inline void QPainter::drawPixmap(const QPoint &p, const QPixmap &pm)
752{
753 drawPixmap(QPointF(p), pm);
754}
755
756inline void QPainter::drawPixmap(const QRect &r, const QPixmap &pm)
757{
758 drawPixmap(QRectF(r), pm, QRectF());
759}
760
761inline void QPainter::drawPixmap(int x, int y, const QPixmap &pm)
762{
763 drawPixmap(QPointF(x, y), pm);
764}
765
766inline void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap &pm)
767{
768 drawPixmap(QRectF(x, y, w, h), pm, QRectF());
769}
770
771inline void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap &pm,
772 int sx, int sy, int sw, int sh)
773{
774 drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
775}
776
777inline void QPainter::drawPixmap(int x, int y, const QPixmap &pm,
778 int sx, int sy, int sw, int sh)
779{
780 drawPixmap(QRectF(x, y, -1, -1), pm, QRectF(sx, sy, sw, sh));
781}
782
783inline void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm, const QRectF &sr)
784{
785 drawPixmap(QRectF(p.x(), p.y(), -1, -1), pm, sr);
786}
787
788inline void QPainter::drawPixmap(const QPoint &p, const QPixmap &pm, const QRect &sr)
789{
790 drawPixmap(QRectF(p.x(), p.y(), -1, -1), pm, sr);
791}
792
793inline void QPainter::drawTextItem(int x, int y, const QTextItem &ti)
794{
795 drawTextItem(QPointF(x, y), ti);
796}
797
798inline void QPainter::drawImage(const QRect &targetRect, const QImage &image, const QRect &sourceRect,
799 Qt::ImageConversionFlags flags)
800{
801 drawImage(QRectF(targetRect), image, QRectF(sourceRect), flags);
802}
803
804inline void QPainter::drawImage(const QPointF &p, const QImage &image, const QRectF &sr,
805 Qt::ImageConversionFlags flags)
806{
807 drawImage(QRectF(p.x(), p.y(), -1, -1), image, sr, flags);
808}
809
810inline void QPainter::drawImage(const QPoint &p, const QImage &image, const QRect &sr,
811 Qt::ImageConversionFlags flags)
812{
813 drawImage(QRect(p.x(), p.y(), -1, -1), image, sr, flags);
814}
815
816
817inline void QPainter::drawImage(const QRectF &r, const QImage &image)
818{
819 drawImage(r, image, QRect(0, 0, image.width(), image.height()));
820}
821
822inline void QPainter::drawImage(const QRect &r, const QImage &image)
823{
824 drawImage(r, image, QRectF(0, 0, image.width(), image.height()));
825}
826
827inline void QPainter::drawImage(const QPoint &p, const QImage &image)
828{
829 drawImage(QPointF(p), image);
830}
831
832inline void QPainter::drawImage(int x, int y, const QImage &image, int sx, int sy, int sw, int sh,
833 Qt::ImageConversionFlags flags)
834{
835 if (sx == 0 && sy == 0 && sw == -1 && sh == -1 && flags == Qt::AutoColor)
836 drawImage(QPointF(x, y), image);
837 else
838 drawImage(QRectF(x, y, -1, -1), image, QRectF(sx, sy, sw, sh), flags);
839}
840
841inline void QPainter::drawStaticText(const QPoint &p, const QStaticText &staticText)
842{
843 drawStaticText(QPointF(p), staticText);
844}
845
846inline void QPainter::drawStaticText(int x, int y, const QStaticText &staticText)
847{
848 drawStaticText(QPointF(x, y), staticText);
849}
850
851inline void QPainter::drawTextItem(const QPoint &p, const QTextItem &ti)
852{
853 drawTextItem(QPointF(p), ti);
854}
855
856inline void QPainter::drawText(const QPoint &p, const QString &s)
857{
858 drawText(QPointF(p), s);
859}
860
861inline void QPainter::drawText(int x, int y, int w, int h, int flags, const QString &str, QRect *br)
862{
863 drawText(QRect(x, y, w, h), flags, str, br);
864}
865
866inline void QPainter::drawText(int x, int y, const QString &s)
867{
868 drawText(QPointF(x, y), s);
869}
870
871inline QRect QPainter::boundingRect(int x, int y, int w, int h, int flags, const QString &text)
872{
873 return boundingRect(QRect(x, y, w, h), flags, text);
874}
875
876inline void QPainter::translate(qreal dx, qreal dy)
877{
878 translate(QPointF(dx, dy));
879}
880
881inline void QPainter::translate(const QPoint &offset)
882{
883 translate(offset.x(), offset.y());
884}
885
886inline void QPainter::setViewport(int x, int y, int w, int h)
887{
888 setViewport(QRect(x, y, w, h));
889}
890
891inline void QPainter::setWindow(int x, int y, int w, int h)
892{
893 setWindow(QRect(x, y, w, h));
894}
895
896#ifndef QT_NO_PICTURE
897inline void QPainter::drawPicture(int x, int y, const QPicture &p)
898{
899 drawPicture(QPoint(x, y), p);
900}
901
902inline void QPainter::drawPicture(const QPoint &pt, const QPicture &p)
903{
904 drawPicture(QPointF(pt), p);
905}
906#endif
907
908QT_END_NAMESPACE
909
910#endif // QPAINTER_H
\inmodule QtGui
Definition qbitmap.h:16
The QColorTransform class is a transformation between color spaces.
\inmodule QtCore\reentrant
Definition qdatastream.h:50
QIODevice * device() const
Returns the device currently assigned to QImageReader, or \nullptr if no device has been assigned.
\inmodule QtGui
Definition qimage.h:37
virtual void drawLines(const QLineF *lines, int lineCount)
The default implementation splits the list of lines in lines into lineCount separate calls to drawPat...
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
virtual void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:47
const QBrush & background() const
Returns the current background brush.
void eraseRect(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:651
CompositionMode compositionMode() const
Returns the current composition mode.
void drawPolyline(const QPolygonF &polyline)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:502
const QPen & pen() const
Returns the painter's current pen.
void setBackground(const QBrush &bg)
Sets the background brush of the painter to the given brush.
void drawLines(const QList< QLineF > &lines)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:482
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
QPainter(QPaintDevice *)
Constructs a painter that begins painting the paint device immediately.
qreal opacity() const
void setWorldMatrixEnabled(bool enabled)
void fillRect(int x, int y, int w, int h, const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:661
void drawPolygon(const QPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:517
void strokePath(const QPainterPath &path, const QPen &pen)
Draws the outline (strokes) the path path with the pen specified by pen.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawText(int x, int y, const QString &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:866
PixmapFragmentHint
\variable QPainter::PixmapFragment::x
Definition qpainter.h:82
@ OpaqueHint
Definition qpainter.h:83
void setViewport(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:886
void drawChord(int x, int y, int w, int h, int a, int alen)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:636
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation.
QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:871
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false.
void translate(qreal dx, qreal dy)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:876
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:726
void drawConvexPolygon(const QPolygon &polygon)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:527
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation.
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
const QFont & font() const
Returns the currently set font used for drawing text.
bool worldMatrixEnabled() const
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the layout direction used by the painter when drawing text, to the specified direction.
void setPen(QPen &&pen)
Definition qpainter.h:156
void restore()
Restores the current painter state (pops a saved state off the stack).
friend class QFontEngine
Definition qpainter.h:433
void rotate(qreal a)
Rotates the coordinate system clockwise.
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
const QTransform & worldTransform() const
Returns the world transformation matrix.
void drawPicture(int x, int y, const QPicture &picture)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:897
const QBrush & brush() const
Returns the painter's current brush.
void setOpacity(qreal opacity)
void drawPoints(const QPolygonF &points)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:574
QFontMetrics fontMetrics() const
Returns the font metrics for the painter if the painter is active.
friend class QFontEngineFT
Definition qpainter.h:435
void drawArc(int x, int y, int w, int h, int a, int alen)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:616
void setPen(const QPen &pen)
Sets the painter's pen to be the given pen.
friend class QOpenGLPaintEngine
Definition qpainter.h:440
void beginNativePainting()
friend class QFontEngineMac
Definition qpainter.h:436
void setClipRect(int x, int y, int w, int h, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the rectangle beginning at (x, y) with the given width ...
Definition qpainter.h:641
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void drawImage(int x, int y, const QImage &image, int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags=Qt::AutoColor)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:832
void drawRects(const QList< QRectF > &rectangles)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:548
friend class QWin32PaintEngine
Definition qpainter.h:441
friend class QRasterPaintEngine
Definition qpainter.h:443
void drawPoint(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:563
friend class QWin32PaintEnginePrivate
Definition qpainter.h:442
void save()
Saves the current painter state (pushes the state onto a stack).
friend class QWidget
Definition qpainter.h:432
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
void setBrush(Qt::BrushStyle style)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void shear(qreal sh, qreal sv)
Shears the coordinate system by ({sh}, {sv}).
void setFont(const QFont &f)
Sets the painter's font to the given font.
friend class QAlphaPaintEngine
Definition qpainter.h:444
QRegion clipRegion() const
Returns the currently set clip region.
void setWindow(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:891
Qt::BGMode backgroundMode() const
Returns the current background mode.
QPainterPath clipPath() const
Returns the current clip path in logical coordinates.
void drawPoints(const QPolygon &points)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:579
friend class QFontEngineWin
Definition qpainter.h:437
void drawRect(int x1, int y1, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:537
QRect viewport() const
Returns the viewport rectangle.
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
void drawEllipse(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:596
void fillRect(int x, int y, int w, int h, const QBrush &)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:656
void fillPath(const QPainterPath &path, const QBrush &brush)
Fills the given path using the given brush.
void setBrush(QBrush &&brush)
Definition qpainter.h:162
QPoint brushOrigin() const
Returns the current brush origin.
void drawStaticText(int left, int top, const QStaticText &staticText)
Definition qpainter.h:846
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
void drawLine(int x1, int y1, int x2, int y2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:465
void drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Definition qpainter.h:584
bool end()
Ends painting.
bool viewTransformEnabled() const
Returns true if view transformation is enabled; otherwise returns false.
void drawTextItem(int x, int y, const QTextItem &ti)
Definition qpainter.h:793
const QTransform & transform() const
Alias for worldTransform().
void resetTransform()
Resets any transformations that were made using translate(), scale(), shear(), rotate(),...
void drawPolygon(const QPolygonF &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:512
QRect window() const
Returns the window rectangle.
void drawPie(int x, int y, int w, int h, int a, int alen)
Definition qpainter.h:626
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:98
@ CompositionMode_Xor
Definition qpainter.h:110
@ RasterOp_SourceAndNotDestination
Definition qpainter.h:135
@ CompositionMode_Destination
Definition qpainter.h:103
@ RasterOp_NotSourceAndNotDestination
Definition qpainter.h:130
@ CompositionMode_Lighten
Definition qpainter.h:118
@ CompositionMode_ColorDodge
Definition qpainter.h:119
@ CompositionMode_DestinationAtop
Definition qpainter.h:109
@ CompositionMode_SourceOver
Definition qpainter.h:99
@ RasterOp_SourceOrNotDestination
Definition qpainter.h:137
@ RasterOp_NotSourceOrNotDestination
Definition qpainter.h:131
@ RasterOp_SourceXorDestination
Definition qpainter.h:129
@ CompositionMode_DestinationOut
Definition qpainter.h:107
@ CompositionMode_Clear
Definition qpainter.h:101
@ CompositionMode_SourceAtop
Definition qpainter.h:108
@ CompositionMode_Plus
Definition qpainter.h:113
@ RasterOp_NotSourceAndDestination
Definition qpainter.h:134
@ CompositionMode_Overlay
Definition qpainter.h:116
@ RasterOp_SourceOrDestination
Definition qpainter.h:127
@ RasterOp_ClearDestination
Definition qpainter.h:138
@ RasterOp_NotSourceOrDestination
Definition qpainter.h:136
@ CompositionMode_Multiply
Definition qpainter.h:114
@ CompositionMode_Darken
Definition qpainter.h:117
@ CompositionMode_DestinationOver
Definition qpainter.h:100
@ RasterOp_NotSource
Definition qpainter.h:133
@ CompositionMode_HardLight
Definition qpainter.h:121
@ CompositionMode_Exclusion
Definition qpainter.h:124
@ CompositionMode_Source
Definition qpainter.h:102
@ CompositionMode_ColorBurn
Definition qpainter.h:120
@ RasterOp_NotSourceXorDestination
Definition qpainter.h:132
@ CompositionMode_Difference
Definition qpainter.h:123
@ RasterOp_NotDestination
Definition qpainter.h:140
@ CompositionMode_SoftLight
Definition qpainter.h:122
@ CompositionMode_DestinationIn
Definition qpainter.h:105
@ CompositionMode_Screen
Definition qpainter.h:115
@ CompositionMode_SourceOut
Definition qpainter.h:106
@ NCompositionModes
Definition qpainter.h:142
@ RasterOp_SourceAndDestination
Definition qpainter.h:128
@ CompositionMode_SourceIn
Definition qpainter.h:104
@ RasterOp_SetDestination
Definition qpainter.h:139
QRectF clipBoundingRect() const
Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rec...
void setViewTransformEnabled(bool enable)
Enables view transformations if enable is true, or disables view transformations if enable is false.
void drawPolyline(const QPolygon &polygon)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:507
void endNativePainting()
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
QPointF brushOriginF() const
Returns the current brush origin.
friend class QPaintEngineExPrivate
Definition qpainter.h:439
friend class QPaintEngine
Definition qpainter.h:438
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(int x, int y, int w, int h, Qt::GlobalColor c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:666
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
QFontInfo fontInfo() const
Returns the font info for the painter if the painter is active.
friend class QTextEngine
Definition qpainter.h:446
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
void setPen(Qt::PenStyle style)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
void setTransform(const QTransform &transform, bool combine=false)
bool testRenderHint(RenderHint hint) const
Definition qpainter.h:417
void drawConvexPolygon(const QPolygonF &polygon)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:522
\inmodule QtCore\reentrant
Definition qpoint.h:232
\inmodule QtCore\reentrant
Definition qpoint.h:30
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:24
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:33
Combined button and popup list for selecting options.
static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags)
Definition qbitmap.cpp:142
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
void(* QImageCleanupFunction)(void *)
Definition qimage.h:34