📄 qpainter.3qt
字号:
.BI "void \fBdrawChord\fR ( int x, int y, int w, int h, int a, int alen )".br.ti -1c.BI "void \fBdrawChord\fR ( const QRect & r, int a, int alen )".br.ti -1c.BI "void \fBdrawLineSegments\fR ( const QPointArray & a, int index = 0, int nlines = -1 )".br.ti -1c.BI "void \fBdrawPolyline\fR ( const QPointArray & a, int index = 0, int npoints = -1 )".br.ti -1c.BI "void \fBdrawPolygon\fR ( const QPointArray & a, bool winding = FALSE, int index = 0, int npoints = -1 )".br.ti -1c.BI "void \fBdrawConvexPolygon\fR ( const QPointArray & pa, int index = 0, int npoints = -1 )".br.ti -1c.BI "void \fBdrawCubicBezier\fR ( const QPointArray & a, int index = 0 )".br.ti -1c.BI "void \fBdrawPixmap\fR ( int x, int y, const QPixmap & pixmap, int sx = 0, int sy = 0, int sw = -1, int sh = -1 )".br.ti -1c.BI "void \fBdrawPixmap\fR ( const QPoint & p, const QPixmap & pm, const QRect & sr )".br.ti -1c.BI "void \fBdrawPixmap\fR ( const QPoint & p, const QPixmap & pm )".br.ti -1c.BI "void \fBdrawPixmap\fR ( const QRect & r, const QPixmap & pm )".br.ti -1c.BI "void \fBdrawImage\fR ( int x, int y, const QImage & image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0 )".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint &, const QImage &, const QRect & sr, int conversionFlags = 0 )".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint & p, const QImage & i, int conversion_flags = 0 )".br.ti -1c.BI "void \fBdrawImage\fR ( const QRect & r, const QImage & i )".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( int x, int y, int w, int h, const QPixmap & pixmap, int sx = 0, int sy = 0 )".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( const QRect & r, const QPixmap & pm, const QPoint & sp )".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( const QRect & r, const QPixmap & pm )".br.ti -1c.BI "void drawPicture ( const QPicture & pic ) \fI(obsolete)\fR".br.ti -1c.BI "void \fBdrawPicture\fR ( int x, int y, const QPicture & pic )".br.ti -1c.BI "void \fBdrawPicture\fR ( const QPoint & p, const QPicture & pic )".br.ti -1c.BI "void \fBfillRect\fR ( int x, int y, int w, int h, const QBrush & brush )".br.ti -1c.BI "void \fBfillRect\fR ( const QRect & r, const QBrush & brush )".br.ti -1c.BI "void \fBeraseRect\fR ( int x, int y, int w, int h )".br.ti -1c.BI "void \fBeraseRect\fR ( const QRect & r )".br.ti -1c.BI "enum \fBTextDirection\fR { Auto, RTL, LTR }".br.ti -1c.BI "void \fBdrawText\fR ( int x, int y, const QString &, int len = -1, TextDirection dir = Auto )".br.ti -1c.BI "void \fBdrawText\fR ( const QPoint &, const QString &, int len = -1, TextDirection dir = Auto )".br.ti -1c.BI "void \fBdrawText\fR ( int x, int y, const QString &, int pos, int len, TextDirection dir = Auto )".br.ti -1c.BI "void \fBdrawText\fR ( const QPoint & p, const QString &, int pos, int len, TextDirection dir = Auto )".br.ti -1c.BI "void \fBdrawText\fR ( int x, int y, int w, int h, int flags, const QString &, int len = -1, QRect * br = 0, QTextParag ** internal = 0 )".br.ti -1c.BI "void \fBdrawText\fR ( const QRect & r, int tf, const QString & str, int len = -1, QRect * brect = 0, QTextParag ** internal = 0 )".br.ti -1c.BI "QRect \fBboundingRect\fR ( int x, int y, int w, int h, int flags, const QString &, int len = -1, QTextParag ** intern = 0 )".br.ti -1c.BI "QRect \fBboundingRect\fR ( const QRect & r, int flags, const QString & str, int len = -1, QTextParag ** internal = 0 )".br.ti -1c.BI "int \fBtabStops\fR () const".br.ti -1c.BI "void \fBsetTabStops\fR ( int ts )".br.ti -1c.BI "int * \fBtabArray\fR () const".br.ti -1c.BI "void \fBsetTabArray\fR ( int * ta )".br.ti -1c.BI "HDC \fBhandle\fR () const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "void \fBredirect\fR ( QPaintDevice * pdev, QPaintDevice * replacement )".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "void \fBqDrawShadeLine\fR ( QPainter * p, int x1, int y1, int x2, int y2, const QColorGroup & g, bool sunken, int lineWidth, int midLineWidth )".br.ti -1c.BI "void \fBqDrawShadeRect\fR ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, int lineWidth, int midLineWidth, const QBrush * fill )".br.ti -1c.BI "void \fBqDrawShadePanel\fR ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, int lineWidth, const QBrush * fill )".br.ti -1c.BI "void \fBqDrawWinButton\fR ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, const QBrush * fill )".br.ti -1c.BI "void \fBqDrawWinPanel\fR ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, bool sunken, const QBrush * fill )".br.ti -1c.BI "void \fBqDrawPlainRect\fR ( QPainter * p, int x, int y, int w, int h, const QColor & c, int lineWidth, const QBrush * fill )".br.in -1c.SH DESCRIPTIONThe QPainter class does low-level painting e.g. on widgets..PPThe painter provides highly optimized functions to do most of the drawing GUI programs require. QPainter can draw everything from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation..PPThe typical use of a painter is:.TPConstruct a painter..TPSet a pen, a brush etc..TPDraw..TPDestroy the painter..PPMostly, all this is done inside a paint event. (In fact, 99% of all QPainter use is in a reimplementation of QWidget::paintEvent(), and the painter is heavily optimized for such use.) Here's one very simple example:.PP.nf.br void SimpleExampleWidget::paintEvent().br {.br QPainter paint( this );.br paint.setPen( Qt::blue );.br paint.drawText( rect(), AlignCenter, "The Text" );.br }.br.fi.PPUsage is simple, and there are many settings you can use:.IP.TPfont() is the currently set font. If you set a font that isn't available, Qt finds a close match. In fact font() returns what you set using setFont() and fontInfo() returns the font actually being used (which may be the same)..IP.TPbrush() is the currently set brush; the color or pattern that's used for filling e.g. circles..IP.TPpen() is the currently set pen; the color or stipple that's used for drawing lines or boundaries..IP.TPbackgroundMode() is \fCOpaque\fR or \fCTransparent\fR, i.e. whether backgroundColor() is used or not..IP.TPbackgroundColor() only applies when backgroundMode() is Opaque and pen() is a stipple. In that case, it describes the color of the background pixels in the stipple..IP.TPrasterOp() is how pixels drawn interact with the pixels already there..IP.TPbrushOrigin() is the origin of the tiled brushes, normally the origin of the window..IP.TPviewport(), window(), worldMatrix() and many more make up the painter's coordinate transformation system. See The Coordinate System for an explanation of this, or see below for a very brief overview of the functions..IP.TPhasClipping() is whether the painter clips at all. (The paint device clips, too.) If the painter clips, it clips to clipRegion()..IP.TPpos() is the current position, set by moveTo() and used by lineTo()..IP.PPNote that some of these settings mirror settings in some paint devices, e.g. QWidget::font(). QPainter::begin() (or the QPainter constructor) copies these attributes from the paint device. Calling, for example, QWidget::setFont() doesn't take effect until the next time a painter begins painting on it..PPsave() saves all of these settings on an internal stack, restore() pops them back..PPThe core functionality of QPainter is drawing, and there are functions to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(), drawEllipse(), drawArc(), drawPie(), drawChord(), drawLineSegments(), drawPolyline(), drawPolygon(), drawConvexPolygon() and drawCubicBezier(). All of these functions take integer coordinates; there are no floating-point versions since we want drawing to be as fast as possible..PPThere are functions to draw pixmaps/images, namely drawPixmap(), drawImage() and drawTiledPixmap(). drawPixmap() and drawImage() produce the same result, except that drawPixmap() is faster on-screen and drawImage() faster and sometimes better on QPrinter and QPicture..PPText drawing is done using drawText(), and when you need fine-grained positioning, boundingRect() tells you where a given drawText() command would draw..PPThere is a drawPicture() function that draws the contents of an entire QPicture using this painter. drawPicture() is the only function that disregards all the painter's settings: the QPicture has its own settings..PPNormally, the QPainter operates on the device's own coordinate system (usually pixels), but QPainter has good support for coordinate transformation. See The Coordinate System for a more general overview and a simple example..PPThe most common functions used are scale(), rotate(), translate() and shear(), all of which operate on the worldMatrix(). setWorldMatrix() can replace or add to the currently set worldMatrix()..PPsetViewport() sets the rectangle on which QPainter operates. The default is the entire device, which is usually fine, except on printers. setWindow() sets the coordinate system, that is, the rectangle that maps to viewport(). What's drawn inside the window() ends up being inside the viewport(). The window's default is the same as the viewport, and if you don't use the transformations, they are optimized away, gaining another little bit of speed..PPAfter all the coordinate transformation is done, QPainter can clip the drawing to an arbitrary rectangle or region. hasClipping() is TRUE if QPainter clips, and clipRegion() returns the clip region. You can set it using either setClipRegion() or setClipRect(). Note that the clipping can be slow. It's all system-dependent, but as a rule of thumb, you can assume that drawing speed is inversely proportional to the number of rectangles in the clip region..PPAfter QPainter's clipping, the paint device may also clip. For example, most widgets clip away the pixels used by child widgets, and most printers clip away an area near the edges of the paper. This additional clipping is not reflected by the return value of clipRegion() or hasClipping()..PPQPainter also includes some less-used functions that are very useful on those occasions when they're needed..PPisActive() indicates whether the painter is active. begin() (and the most usual constructor) makes it active. end() (and the destructor) deactivates it. If the painter is active, device() returns the paint device on which the painter paints..PPSometimes it is desirable to make someone else paint on an unusual QPaintDevice. QPainter supports a static function to do this, redirect(). We recommend not using it, but for some hacks it's perfect..PPsetTabStops() and setTabArray() can change where the tab stops are, but these are very seldomly used..PP\fBWarning:\fR Note that QPainter does not attempt to work around coordinate limitations in the underlying window system. Some platforms may behave incorrectly with coordinates as small as +/-4000..PPSee also QPaintDevice, QWidget, QPixmap, QPrinter, QPicture, Application Walkthrough, Coordinate System Overview, Graphics Classes, and Image Processing Classes..SS "Member Type Documentation".SH "QPainter::CoordinateMode".TP\fCQPainter::CoordDevice\fR.TP\fCQPainter::CoordPainter\fR.PPSee also clipRegion()..SH "QPainter::TextDirection".TP\fCQPainter::Auto\fR.TP\fCQPainter::RTL\fR - right to left.TP\fCQPainter::LTR\fR - left to right.PPSee also drawText()..SH MEMBER FUNCTION DOCUMENTATION.SH "QPainter::QPainter ()"Constructs a painter..PPNotice that all painter settings (setPen, setBrush etc.) are reset to default values when begin() is called..PPSee also begin() and end()..SH "QPainter::QPainter ( const QPaintDevice * pd, bool unclipped = FALSE )"Constructs a painter that begins painting the paint device \fIpd\fR immediately. Depending on the underlying graphic system the painter will paint over children of the paintdevice if \fIunclipped\fR is TRUE..PPThis constructor is convenient for short-lived painters, e.g. in a paint event and should be used only once. The constructor calls begin() for you and the QPainter destructor automatically calls end()..PPHere's an example using begin() and end():.PP.nf.br void MyWidget::paintEvent( QPaintEvent * ).br {.br QPainter p;.br p.begin( this );.br p.drawLine( ... ); // drawing code.br p.end();.br }.br.fi.PPThe same example using this constructor:.PP.nf.br
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -