⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpainter.3qt

📁 Trolltech公司发布的基于C++图形开发环境
💻 3QT
📖 第 1 页 / 共 5 页
字号:
.ti -1c.BI "void \fBdrawQuadBezier\fR ( const QPointArray &, int " "index" "=0 ) ".br.ti -1c.BI "void \fBdrawPixmap\fR ( int " "x" ", int " "y" ", const QPixmap &, int " "sx" "=0, int " "sy" "=0, int " "sw" "=-1, int " "sh" "=-1 ) ".br.ti -1c.BI "void \fBdrawPixmap\fR ( const QPoint &, const QPixmap &, const QRect & sr ) ".br.ti -1c.BI "void \fBdrawPixmap\fR ( const QPoint &, const QPixmap & ) ".br.ti -1c.BI "void \fBdrawImage\fR ( int " "x" ", int " "y" ", const QImage &, int " "sx" "=0, int " "sy" "=0, int " "sw" "=-1, int " "sh" "=-1 ) ".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint &, const QImage &, const QRect & sr ) ".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint &, const QImage & ) ".br.ti -1c.BI "void \fBdrawImage\fR ( int " "x" ", int " "y" ", const QImage &, int " "sx" ", int " "sy" ", int " "sw" ", int " "sh" ", int conversion_flags ) ".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint &, const QImage &, const QRect & " "sr" ", int conversion_flags ) ".br.ti -1c.BI "void \fBdrawImage\fR ( const QPoint &, const QImage &, int conversion_flags ) ".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( int " "x" ", int " "y" ", int " "w" ", int " "h" ", const QPixmap &, int " "sx" "=0, int " "sy" "=0 ) ".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( const QRect &, const QPixmap &, const QPoint & ) ".br.ti -1c.BI "void \fBdrawTiledPixmap\fR ( const QRect &, const QPixmap & ) ".br.ti -1c.BI "void \fBdrawPicture\fR ( const QPicture & ) ".br.ti -1c.BI "void \fBfillRect\fR ( int " "x" ", int " "y" ", int " "w" ", int " "h" ", const QBrush & ) ".br.ti -1c.BI "void \fBfillRect\fR ( const QRect &, const QBrush & ) ".br.ti -1c.BI "void \fBeraseRect\fR ( int " "x" ", int " "y" ", int " "w" ", int h ) ".br.ti -1c.BI "void \fBeraseRect\fR ( const QRect & ) ".br.ti -1c.BI "void \fBdrawText\fR ( int " "x" ", int " "y" ", const QString &, int " "len" " = -1 ) ".br.ti -1c.BI "void \fBdrawText\fR ( const QPoint &, const QString &, int " "len" " = -1 ) ".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, char ** " "internal" "=0 ) ".br.ti -1c.BI "void \fBdrawText\fR ( const QRect &, int " "flags" ", const QString &, int " "len" " = -1, QRect * " "br" "=0, char ** " "internal" "=0 ) ".br.ti -1c.BI "QRect \fBboundingRect\fR ( int " "x" ", int " "y" ", int " "w" ", int " "h" ", int " "flags" ", const QString &, int " "len" " = -1, char ** " "intern" "=0 ) ".br.ti -1c.BI "QRect \fBboundingRect\fR ( const QRect &, int " "flags" ", const QString &, int " "len" " = -1, char ** " "intern" "=0 ) ".br.ti -1c.BI "int \fBtabStops\fR () const".br.ti -1c.BI "void \fBsetTabStops\fR ( int ) ".br.ti -1c.BI "int* \fBtabArray\fR () const".br.ti -1c.BI "void \fBsetTabArray\fR ( int * ) ".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "void \fBredirect\fR ( QPaintDevice * " "pdev" ", QPaintDevice * replacement ) ".br.ti -1c.BI "void \fBinitialize\fR () ".br.ti -1c.BI "void \fBcleanup\fR () ".br.in -1c.SH RELATED FUNCTION DOCUMENTATION(Note that these are not member functions.).in +1c.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.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 \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.in -1c.SH DESCRIPTIONThe QPainter class paints on paint devices..PPThe painter provides efficient graphics rendering on any QPaintDevice object. 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:.IP 1Construct a painter..IP 2Set a pen, a brush etc..IP 3Draw..IP 4Destroy 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()). 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    }.fi.PPSimple. However, there are many settings you may use: .TPfont() is the currently set font. If you set a font that isn't available, Qt finds a close match. In that case font() returns what you set using setFont() and fontInfo() returns the font actually being used..TPbrush() is the currently set brush; the color or pattern that's used for filling e.g. circles..TPpen() is the currently set pen; the color or stipple that's used for drawing lines or boundaries..TPbackgroundMode() is \fCOpaque\fR or \fCTransparent,\fR ie. whether backgroundColor() is used or not..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..TPrasterOp() is how pixels drawn interact with the data already there..TPbrushOrigin() is the origin of the tiled brushes, normally the origin of the window..TPviewport(), window(), worldMatrix() and many more make up the painter's coordinate transformation system. See The Coordinate System for an explanation of this, or a paragraph below for a quick overview of the functions..TPclipping() is whether the painter clips at all. (The paint device clips, too.) If the painter clips, it clips to clipRegion()..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, changing calling e.g. 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(), and drawQuadBezier()..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() 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 walkthrough of 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 matrix()..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 draws 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 a little speed..PPAfter all the coordinate transformation is done, QPainter can clip the drawing to and 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 too will clip a bit. 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 \fInot\fR reflected by the return value of clipRegion() or hasClipping()..PPFinally, QPainter includes some little-used functions that are very handy the few times you need them..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 and Coordinate System Overview.PPExamples:.(lmovies/main.cpp splitter/splitter.cpp qtimage/qtimage.cpp scrollview/scrollview.cpp drawdemo/drawdemo.cpp picture/picture.cpp drawlines/connect.cpp forever/forever.cpp progress/progress.cpp qmag/qmag.cpp menu/menu.cpp xform/xform.cpp grapher/grapher.cpp trivial/trivial.cpp desktop/desktop.cpp.)l.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 )"Constructs a painter that begins painting the paint device \fIpd\fR immediately..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    }.fi.PPThe same example using this constructor:.PP.nf.br    void MyWidget::paintEvent( QPaintEvent * ).br    {.br        QPainter p( this );.br        p.drawLine( ... );      // drawing code.br    }.fi.PPSee also begin() and end()..SH "QPainter::QPainter ( const QPaintDevice * pd, const QWidget * copyAttributes )"Constructs a painter that begins painting the paint device \fIpd\fR immediately, with the default arguments taken from \fIcopyAttributes.\fR.PPSee also begin()..SH "QPainter::~QPainter ()"Destructs 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 )"Begins painting the paint device \fIpd\fR and returns TRUE if successful, or FALSE if an error occurs..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.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:.(ldrawdemo/drawdemo.cpp picture/picture.cpp desktop/desktop.cpp.)l.SH "bool QPainter::begin ( const QPaintDevice * pd, const QWidget * copyAttributes )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPThis version opens the painter on a paint device \fIpd\fR and sets the initial pen, background color and font from \fIcopyAttributes.\fR This is equivalent with:.PP.nf

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -