📄 qpainter.3qt
字号:
p.drawLine( ... ); // drawing code.br }.br.fi.PPSince the constructor cannot provide feedback when the initialization of the painter failed you should rather use begin() and end() to paint on external devices, e.g. printers..PPSee also begin() and end()..SH "QPainter::QPainter ( const QPaintDevice * pd, const QWidget * copyAttributes, bool unclipped = FALSE )"Constructs a painter that begins painting the paint device \fIpd\fR immediately, with the default arguments taken from \fIcopyAttributes\fR. The painter will paint over children of the paint device if \fIunclipped\fR is TRUE (although this is not supported on all platforms)..PPSee also begin()..SH "QPainter::~QPainter ()"Destroys the painter..SH "const QColor & QPainter::backgroundColor () const"Returns the current background color..PPSee also setBackgroundColor() and QColor..SH "BGMode QPainter::backgroundMode () const"Returns the current background mode..PPSee also setBackgroundMode() and BGMode..SH "bool QPainter::begin ( const QPaintDevice * pd, bool unclipped = FALSE )"Begins painting the paint device \fIpd\fR and returns TRUE if successful; otherwise returns FALSE. If \fIunclipped\fR is TRUE, the painting will not be clipped at the paint device's boundaries, (although this is not supported by all platforms)..PPThe errors that can occur are serious problems, such as these:.PP.nf.br p->begin( 0 ); // impossible - paint device cannot be 0.br.br QPixmap pm( 0, 0 );.br p->begin( pm ); // impossible - pm.isNull();.br.br p->begin( myWidget );.br p2->begin( myWidget ); // impossible - only one painter at a time.br.fi.PPNote that most of the time, you can use one of the constructors instead of begin(), and that end() is automatically done at destruction..PP\fBWarning:\fR A paint device can only be painted by one painter at a time..PPSee also end() and flush()..PPExamples:.)l aclock/aclock.cpp, application/application.cpp, desktop/desktop.cpp, hello/hello.cpp, picture/picture.cpp, t10/cannon.cpp, and xform/xform.cpp..SH "bool QPainter::begin ( const QPaintDevice * pd, const QWidget * copyAttributes, bool unclipped = FALSE )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis version opens the painter on a paint device \fIpd\fR and sets the initial pen, background color and font from \fIcopyAttributes\fR, painting over the paint device's children when \fIunclipped\fR is TRUE. This is equivalent to:.PP.nf.br QPainter p;.br p.begin( pd );.br p.setPen( copyAttributes->foregroundColor() );.br p.setBackgroundColor( copyAttributes->backgroundColor() );.br p.setFont( copyAttributes->font() );.br.fi.PPThis begin function is convenient for double buffering. When you draw in a pixmap instead of directly in a widget (to later bitBlt the pixmap into the widget) you will need to set the widget's font etc. This function does exactly that..PPExample:.PP.nf.br void MyWidget::paintEvent( QPaintEvent * ).br {.br QPixmap pm(size());.br QPainter p;.br p.begin(&pm, this);.br // ... potentially flickering paint operation ....br p.end();.br bitBlt(this, 0, 0, &pm);.br }.br.fi.PPSee also end()..SH "QRect QPainter::boundingRect ( int x, int y, int w, int h, int flags, const QString &, int len = -1, QTextParag ** intern = 0 )"Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function using the first \fIlen\fR characters of the string if \fIlen\fR is > -1, or the whole of the string if \fIlen\fR is -1. The drawing, and hence the bounding rectangle, is constrained to the rectangle that begins at point \fI(x, y)\fR with width \fIw\fR and hight \fIh\fR..PPThe \fIflags\fR argument is the bitwise OR of the following flags: <center>.nf.TSl - l. Flag Meaning AlignAuto aligns according to the language, usually left. AlignLeft aligns to the left border. AlignRight aligns to the right border. AlignHCenter aligns horizontally centered. AlignTop aligns to the top border. AlignBottom aligns to the bottom border. AlignVCenter aligns vertically centered. AlignCenter (== AlignHCenter | AlignVCenter). SingleLine ignores newline characters in the text. ExpandTabs expands tabs. ShowPrefix interprets "&x" as " WordBreak.TE.fi</center>.PPHorizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop..PPIf several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined..PPThe \fIintern\fR parameter should not be used..PPSee also Qt::TextFlags..SH "QRect QPainter::boundingRect ( const QRect & r, int flags, const QString & str, int len = -1, QTextParag ** internal = 0 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function using the first \fIlen\fR characters from \fIstr\fR if \fIlen\fR is > -1, or the whole of \fIstr\fR if \fIlen\fR is -1. The drawing, and hence the bounding rectangle, is constrained to the rectangle \fIr\fR..PPThe \fIinternal\fR parameter should not be used..PPSee also drawText(), fontMetrics(), QFontMetrics::boundingRect(), and Qt::TextFlags..SH "const QBrush & QPainter::brush () const"Returns the painter's current brush..PPSee also QPainter::setBrush()..PPExamples:.)l themes/metal.cpp and themes/wood.cpp..SH "const QPoint & QPainter::brushOrigin () const"Returns the brush origin currently set..PPSee also setBrushOrigin()..SH "QRegion QPainter::clipRegion ( CoordinateMode m = CoordDevice ) const"Returns the currently set clip region. Note that the clip region is given in physical device coordinates and \fInot\fR subject to any coordinate transformation if \fIm\fR is equal to CoordDevice (the default). If \fIm\fR equals CoordPainter the returned region is in model coordinates..PPSee also setClipRegion(), setClipRect(), setClipping(), and QPainter::CoordinateMode..PPExample: themes/wood.cpp..SH "QPaintDevice * QPainter::device () const"Returns the paint device on which this painter is currently painting, or 0 if the painter is not active..PPSee also QPaintDevice::paintingActive()..PPExamples:.)l helpviewer/helpwindow.cpp and listboxcombo/listboxcombo.cpp..SH "void QPainter::drawArc ( int x, int y, int w, int h, int a, int alen )"Draws an arc defined by the rectangle \fI(x, y, w, h)\fR, the start angle \fIa\fR and the arc length \fIalen\fR..PPThe angles \fIa\fR and \fIalen\fR are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of \fIa\fR and \fIalen\fR mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position..PPExample:.PP.nf.br QPainter p( myWidget );.br p.drawArc( 10,10, 70,100, 100*16, 160*16 ); // draws a "(" arc.br.fi.PPSee also drawPie() and drawChord()..SH "void QPainter::drawArc ( const QRect & r, int a, int alen )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the arc that fits inside the rectangle \fIr\fR with start angle \fIa\fR and arc length \fIalen\fR..SH "void QPainter::drawChord ( int x, int y, int w, int h, int a, int alen )"Draws a chord defined by the rectangle \fI(x, y, w, h)\fR, the start angle \fIa\fR and the arc length \fIalen\fR..PPThe chord is filled with the current brush()..PPThe angles \fIa\fR and \fIalen\fR are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of \fIa\fR and \fIalen\fR mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position..PPSee also drawArc() and drawPie()..SH "void QPainter::drawChord ( const QRect & r, int a, int alen )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws a chord that fits inside the rectangle \fIr\fR with start angle \fIa\fR and arc length \fIalen\fR..SH "void QPainter::drawConvexPolygon ( const QPointArray & pa, int index = 0, int npoints = -1 )"Draws the convex polygon defined by the \fInpoints\fR points in \fIpa\fR starting at \fIpa[index]\fR (\fIindex\fR defaults to 0)..PPIf the supplied polygon is not convex, the results are undefined..PPOn some platforms (e.g. X Window), this is faster than drawPolygon()..PPExample: aclock/aclock.cpp..SH "void QPainter::drawCubicBezier ( const QPointArray & a, int index = 0 )"Draws a cubic Bezier curve defined by the control points in \fIa\fR, starting at \fIa[index]\fR (\fIindex\fR defaults to 0)..PPControl points after \fIa[index + 3]\fR are ignored. Nothing happens if there aren't enough control points..SH "void QPainter::drawEllipse ( int x, int y, int w, int h )"Draws an ellipse with center at \fI(x + w/2, y + h/2)\fR and size \fI(w, h)\fR..PPExamples:.)l drawdemo/drawdemo.cpp, picture/picture.cpp, and tictac/tictac.cpp..SH "void QPainter::drawEllipse ( const QRect & r )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the ellipse that fits inside rectangle \fIr\fR..SH "void QPainter::drawImage ( int x, int y, const QImage & image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0 )"Draws at (\fIx\fR, \fIy\fR) the \fIsw\fR by \fIsh\fR area of pixels from (\fIsx\fR, \fIsy\fR) in \fIimage\fR, using \fIconversionFlags\fR if the image needs to be converted to a pixmap. The default value for \fIconversionFlags\fR is 0; see convertFromImage() for information about what other values do..PPThis function may convert \fIimage\fR to a pixmap and then draw it, if device() is a QPixmap or a QWidget, or else draw it directly, if device() is a QPrinter or QPicture..PPCurrently alpha masks of the image are ignored when painting on a QPrinter..PPSee also drawPixmap() and QPixmap::convertFromImage()..PPExample: canvas/canvas.cpp..SH "void QPainter::drawImage ( const QPoint &, const QImage &, const QRect & sr, int conversionFlags = 0 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the rectangle \fIsr\fR from the image at the given point..SH "void QPainter::drawImage ( const QPoint & p, const QImage & i, int conversion_flags = 0 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the image \fIi\fR at point \fIp\fR..PPIf the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the \fIconversion_flags\fR to specify how you'd prefer this to happen..PPSee also Qt::ImageConversionFlags..SH "void QPainter::drawImage ( const QRect & r, const QImage & i )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the image \fIi\fR into the rectangle \fIr\fR. The image will be scaled to fit the rectangle if image and rectangle dimensions differ..SH "void QPainter::drawLine ( int x1, int y1, int x2, int y2 )"Draws a line from (\fIx1\fR, \fIy1\fR) to (\fIx2\fR, \fIy2\fR) and sets the current pen position to (\fIx2\fR, \fIy2\fR)..PPSee also pen()..PPExamples:.)l aclock/aclock.cpp, drawlines/connect.cpp, progress/progress.cpp, splitter/splitter.cpp, themes/metal.cpp, and themes/wood.cpp..SH "void QPainter::drawLine ( const QPoint & p1, const QPoint & p2 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws a line from point \fIp1\fR to point \fIp2\fR..SH "void QPainter::drawLineSegments ( const QPointArray & a, int index = 0, int nlines = -1 )"Draws \fInlines\fR separate lines from points defined in \fIa\fR, starting at \fIa[index]\fR (\fIindex\fR defaults to 0). If \fInlines\fR is -1 (the default) all points until the end of the array are used (i.e. (a.size()-index)/2 lines are drawn)..PPDraws the 1st line from \fIa[index]\fR to \fIa[index+1]\fR. Draws the 2nd line from \fIa[index+2]\fR to \fIa[index+3]\fR etc..PPSee also drawPolyline(), drawPolygon(), and QPen..SH "void QPainter::drawPicture ( int x, int y, const QPicture & pic )"Replays the picture \fIpic\fR translated by (\fIx\fR, \fIy\fR)..PPThis function does exactly the same as QPicture::play() when called with (\fIx\fR, \fIy\fR) = (0, 0)..PPExamples:.)l picture/picture.cpp and xform/xform.cpp..SH "void QPainter::drawPicture ( const QPicture & pic )"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPUse one of the other QPainter::drawPicture() functions with a (0, 0) offset instead..SH "void QPainter::drawPicture ( const QPoint & p, const QPicture & pic )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws picture \fIpic\fR at point \fIp\fR..SH "void QPainter::drawPie ( int x, int y, int w, int h, int a, int alen )"Draws a pie defined by the rectangle \fI(x, y, w, h)\fR, the start angle \fIa\fR and the arc length \fIalen\fR..PPThe pie is filled with the current brush()..PPThe angles \fIa\fR and \fIalen\fR are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). Positive values of \fIa\fR and \fIalen\fR mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position..PPSee also drawArc() and drawChord()..PPExamples:.)l drawdemo/drawdemo.cpp, t10/cannon.cpp, and t9/cannon.cpp..SH "void QPainter::drawPie ( const QRect & r, int a, int alen )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws a pie segment that fits inside the rectangle \fIr\fR with start angle \fIa\fR and arc length \fIalen\fR..SH "void QPainter::drawPixmap ( int x, int y, const QPixmap & pixmap, int sx = 0, int sy = 0, int sw = -1, int sh = -1 )"Draws a pixmap at \fI(x, y)\fR by copying a part of \fIpixmap\fR into the paint device..PP\fI(x, y)\fR specifies the top-left point in the paint device that is to be drawn onto. \fI(sx, sy)\fR specifies the top-left point in \fIpixmap\fR that is to be drawn. The default is (0, 0)..PP\fI(sw, sh)\fR specifies the size of the pixmap that is to be drawn. The default, (-1, -1), means all the way to the bottom right of the pixmap..PPCurrently the mask of the pixmap or it's alpha channel are ignored when painting on a QPrinter..PPSee also bitBlt() and QPixmap::setMask()..PPExamples:.)l canvas/canvas.cpp, picture/picture.cpp, qdir/qdir.cpp, qmag/qmag.cpp, showimg/showimg.cpp, t10/cannon.cpp, and xform/xform.cpp..SH "void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm, const QRect & sr )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the rectangle \fIsr\fR of pixmap \fIpm\fR with its origin at point \fIp\fR..SH "void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the pixmap \fIpm\fR with its origin at point \fIp\fR..SH "void QPainter::drawPixmap ( const QRect & r, const QPixmap & pm )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPDraws the pixmap \fIpm\fR into the rectangle \fIr\fR. The pixmap is scaled to fit the rectangle, if image and rectangle size disagree..SH "void QPainter::drawPoint ( int x, int y )"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -