📄 qpainter.3qt
字号:
.br QPainter p;.br p.begin( pd );.br p.setPen( copyAttributes->foregroundColor() );.br p.setBackgroundColor( copyAttributes->backgroundColor() );.br p.setFont( copyAttributes->font() );.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 widgets'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 // ... potential flickering paint operation ....br p.end();.br bitBlt(this, 0, 0, &pm);.br }.fi.PPSee also end()..SH "QRect QPainter::boundingRect ( int x, int y, int w, int h, int tf, const QString & str, int len = -1, char ** internal=0 )"Returns the bounding rectangle of the aligned text that would be printed with the corresponding drawText() function (the first \fIlen\fR characters from \fIstr).\fR The drawing, and hence the bounding rectangle, is constrained to the rectangle \fI(x,y,w,h).\fR.PPIf \fIlen\fR is negative (default value), the whole string is used..PPThe \fItf\fR argument is the bitwise OR of the following flags: .TP\fCAlignLeft\fR aligns to the left border..TP\fCAlignRight\fR aligns to the right border..TP\fCAlignHCenter\fR aligns horizontally centered..TP\fCAlignTop\fR aligns to the top border..TP\fCAlignBottom\fR aligns to the bottom border..TP\fCAlignVCenter\fR aligns vertically centered.TP\fCAlignCenter\fR (= \fCAlignHCenter\fR | AlignVCenter).TP\fCSingleLine\fR ignores newline characters in the text..TP\fCExpandTabs\fR expands tabulators..TP\fCShowPrefix\fR interprets "&x" as "x" underlined..TP\fCWordBreak\fR breaks the text to fit the rectangle..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..PPThese flags are defined in qnamespace.h..PPSee also drawText(), fontMetrics(), QFontMetrics::boundingRect() and Qt::AlignmentFlags..SH "QRect QPainter::boundingRect ( const QRect & r, int tf, const QString &, int len = -1, char ** i=0 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "const QBrush & QPainter::brush () const"Returns the current painter brush..PPSee also QPainter::setBrush()..SH "const QPoint & QPainter::brushOrigin () const"Returns the brush origin currently set..PPSee also setBrushOrigin()..SH "void QPainter::cleanup () \fC[static]\fR"Internal function that cleans up the painter..SH "const QRegion & QPainter::clipRegion () 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..PPSee also setClipRegion(), setClipRect() and setClipping()..SH "QPaintDevice * QPainter::device () const"Returns the paint device on which this painter is currently painting, or null if the painter is not active..PPSee also QPaintDevice::paintingActive()..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 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.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 differs from the above function only in what argument(s) it accepts..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 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 differs from the above function only in what argument(s) it accepts..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:.(ldrawdemo/drawdemo.cpp picture/picture.cpp.)l.SH "void QPainter::drawEllipse ( const QRect & r )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawImage ( int x, int y, const QImage & image, int sx, int sy, int sw, int sh, int conversion_flags )"Draws at (\fIx, y)\fR the \fIsw\fR by \fIsh\fR area of pixels from (\fIsx, sy)\fR in \fIimage,\fR using \fIconversion_flags\fR if the image needs to be converted to a pixmap..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..PPSee also drawPixmap() and QPixmap::convertFromImage()..SH "void QPainter::drawImage ( const QPoint &, const QImage & )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawImage ( const QPoint &, const QImage &, const QRect & sr )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawImage ( const QPoint &, const QImage &, const QRect & sr, int conversion_flags )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawImage ( const QPoint &, const QImage &, int conversion_flags )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawImage ( int x, int y, const QImage & image, int sx=0, int sy=0, int sw=-1, int sh=-1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawLine ( int x1, int y1, int x2, int y2 )"Draws a line from \fI(x1,y2)\fR to \fI(x2,y2)\fR and sets \fI(x2,y2)\fR to be the new current pen position..PPSee also QPen..PPExamples:.(lsplitter/splitter.cpp scrollview/scrollview.cpp drawlines/connect.cpp progress/progress.cpp grapher/grapher.cpp.)l.SH "void QPainter::drawLine ( const QPoint & p1, const QPoint & p2 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..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 a[\fIindex]\fR (\fIindex\fR defaults to 0). If \fInlines\fR is -1 (the defauls) 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 ( const QPicture & pic )"Replays the picture \fIpic.\fR.PPThis function does exactly the same as QPicture::play()..PPExamples:.(lpicture/picture.cpp.)l.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 clockwise direction. Zero degrees is at the 3'o clock position..PPSee also drawArc() and drawChord()..PPExamples:.(ldrawdemo/drawdemo.cpp grapher/grapher.cpp.)l.SH "void QPainter::drawPie ( const QRect & r, int a, int alen )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..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 specify the top-left point in the paint device that is to be drawn onto. \fI(sx,sy)\fR specify the top-left point in \fIpixmap\fR that is to be drawn (the default is (0,0). \fI(sw,sh)\fR specify the size of the pixmap that is to be drawn (the default, (-1,-1), means all the way to the right/bottom of the pixmap)..PPSee also bitBlt() and QPixmap::setMask()..PPExamples:.(lmovies/main.cpp qtimage/qtimage.cpp scrollview/scrollview.cpp picture/picture.cpp qmag/qmag.cpp grapher/grapher.cpp.)l.SH "void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPThis version of the call draws the entire pixmap..SH "void QPainter::drawPixmap ( const QPoint & p, const QPixmap & pm, const QRect & sr )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawPoint ( int x, int y )"Draws/plots a single point at \fI(x,y)\fR using the current pen..PPSee also QPen..PPExamples:.(ldrawlines/connect.cpp desktop/desktop.cpp.)l.SH "void QPainter::drawPoint ( const QPoint & p )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawPoints ( const QPointArray & a, int index=0, int npoints=-1 )"Draws/plots an array of points using the current pen..PPIf \fIindex\fR is non-zero (the default is zero) only points from \fIindex\fR are drawn. If \fInpoints\fR is negative (the default) the rest of the points from \fIindex\fR are drawn. If is is zero or greater, \fInpoints\fR points are drawn..SH "void QPainter::drawPolygon ( const QPointArray & a, bool winding=FALSE, int index=0, int npoints=-1 )"Draws the polygon defined by the \fInpoints\fR points in \fIa\fR starting at \fIa[index].\fR (\fIindex\fR defaults to 0.).PPIf \fInpoints\fR is -1 (the default) all points until the end of the array are used (i.e. a.size()-index line segments define the polygon)..PPThe first point is always connected to the last point..PPThe polygon is filled with the current brush(). If \fIwinding\fR is TRUE, the polygon is filled using the winding fill algorithm. If \fIwinding\fR is FALSE, the polygon is filled using the even-odd (alternative) fill algorithm..PPSee also drawLineSegments(), drawPolyline() and QPen..PPExamples:.(lpicture/picture.cpp desktop/desktop.cpp.)l.SH "void QPainter::drawPolyline ( const QPointArray & a, int index=0, int npoints=-1 )"Draws the polyline defined by the \fInpoints\fR points in \fIa\fR starting at \fIa[index].\fR (\fIindex\fR defaults to 0.).PPIf \fInpoints\fR is -1 (the default) all points until the end of the array are used (i.e. a.size()-index-1 line segments are drawn)..PPSee also drawLineSegments(), drawPolygon() and QPen..SH "void QPainter::drawQuadBezier ( 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::drawRect ( int x, int y, int w, int h )"Draws a rectangle with upper left corner at \fI(x,y)\fR and with width \fIw\fR and height \fIh.\fR.PPSee also QPen and drawRoundRect()..PPExamples:.(ldrawdemo/drawdemo.cpp picture/picture.cpp forever/forever.cpp grapher/grapher.cpp trivial/trivial.cpp.)l.SH "void QPainter::drawRect ( const QRect & r )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawRoundRect ( int x, int y, int w, int h, int xRnd, int yRnd )"Draws a rectangle with round corners at \fI(x,y),\fR with width \fIw\fR and height \fIh.\fR.PPThe \fIxRnd\fR and \fIyRnd\fR arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness..PPThe width and height include all of the drawn lines..PPSee also drawRect() and QPen..PPExamples:.(ldrawdemo/drawdemo.cpp.)l.SH "void QPainter::drawRoundRect ( const QRect & r, int xRnd, int yRnd )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawRoundRect ( const QRect & )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPAs the main version of the function, but with the roundness arguments fixed at 25..SH "void QPainter::drawRoundRect ( int x, int y, int w, int h )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPAs the main version of the function, but with the roundness arguments fixed at 25..SH "void QPainter::drawText ( int x, int y, const QString & str, int len = -1 )"Draws at most \fIlen\fR characters from \fIstr\fR at position \fI(x,y).\fR.PP\fI(x,y)\fR is the base line position. Note that the meaning of \fIy\fR is not the same for the two drawText() varieties..PPExamples:.(lmovies/main.cpp scrollview/scrollview.cpp drawdemo/drawdemo.cpp picture/picture.cpp progress/progress.cpp menu/menu.cpp grapher/grapher.cpp trivial/trivial.cpp desktop/desktop.cpp.)l.SH "void QPainter::drawText ( int x, int y, int w, int h, int tf, const QString & str, int len = -1, QRect * brect=0, char ** internal=0 )"Draws at most \fIlen\fR characters from \fIstr\fR in the rectangle \fI(x,y,w,h).\fR.PPNote that the meaning of \fIy\fR is not the same for the two drawText() varieties..PPThis function draws formatted text. The \fItf\fR text formatting is really of type Qt::AlignmentFlags..PPHorizontal alignment defaults to AlignLeft and vertical alignment defaults to AlignTop..PP\fIbrect\fR (if non-null) is set to the actual bounding rectangle of the output. \fIinternal\fR is, yes, internal..PPSee also boundingRect()..SH "void QPainter::drawText ( const QPoint & p, const QString &, int len = -1 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawText ( const QRect & r, int tf, const QString &, int len = -1, QRect * br=0, char ** i=0 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QPainter::drawTiledPixmap ( int x, int y, int w, int h, const QPixmap & pixmap, int sx=0, int sy=0 )"Draws a tiled \fIpixmap\fR in the specified rectangle..PP\fI(x,y)\fR specify the top-left point in the paint device that is to be drawn onto. \fI(sx,sy)\fR specify the top-left point in \fIpixmap\fR that is to be drawn (the default is (0,0)..PPCalling drawTiledPixmap() is similar to calling drawPixmap() several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -