CopperSpice API  1.7.2
QStylePainter Class Reference

The QStylePainter class is a convenience class for drawing QStyle elements inside a widget. More...

Inheritance diagram for QStylePainter:
QPainter

Public Methods

 QStylePainter ()
 
 QStylePainter (QPaintDevice *device, QWidget *widget)
 
 QStylePainter (QWidget *widget)
 
bool begin (QPaintDevice *pd, QWidget *widget)
 
bool begin (QWidget *widget)
 
void drawComplexControl (QStyle::ComplexControl cc, const QStyleOptionComplex &option)
 
void drawControl (QStyle::ControlElement ce, const QStyleOption &option)
 
void drawItemPixmap (const QRect &r, int flags, const QPixmap &pixmap)
 
void drawItemText (const QRect &r, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole)
 
void drawPrimitive (QStyle::PrimitiveElement pe, const QStyleOption &option)
 
QStylestyle () const
 
- Public Methods inherited from QPainter
 QPainter ()
 
 QPainter (QPaintDevice *device)
 
 ~QPainter ()
 
const QBrushbackground () const
 
Qt::BGMode backgroundMode () const
 
bool begin (QPaintDevice *device)
 
void beginNativePainting ()
 
QRect boundingRect (const QRect &rectangle, int flags, const QString &text)
 
QRectF boundingRect (const QRectF &rectangle, const QString &text, const QTextOption &option=QTextOption ())
 
QRectF boundingRect (const QRectF &rectangle, int flags, const QString &text)
 
QRect boundingRect (int x, int y, int w, int h, int flags, const QString &text)
 
const QBrushbrush () const
 
QPoint brushOrigin () const
 
QRectF clipBoundingRect () const
 
QPainterPath clipPath () const
 
QRegion clipRegion () const
 
QMatrix combinedMatrix () const
 
QTransform combinedTransform () const
 
CompositionMode compositionMode () const
 
QPaintDevicedevice () const
 
const QMatrixdeviceMatrix () const
 
const QTransformdeviceTransform () const
 
void drawArc (const QRect &rectangle, int startAngle, int spanAngle)
 
void drawArc (const QRectF &rectangle, int startAngle, int spanAngle)
 
void drawArc (int x, int y, int w, int h, int startAngle, int spanAngle)
 
void drawChord (const QRect &rectangle, int startAngle, int spanAngle)
 
void drawChord (const QRectF &rectangle, int startAngle, int spanAngle)
 
void drawChord (int x, int y, int w, int h, int startAngle, int spanAngle)
 
void drawConvexPolygon (const QPoint *points, int pointCount)
 
void drawConvexPolygon (const QPointF *points, int pointCount)
 
void drawConvexPolygon (const QPolygon &polygon)
 
void drawConvexPolygon (const QPolygonF &polygon)
 
void drawEllipse (const QPoint &center, int rx, int ry)
 
void drawEllipse (const QPointF &center, qreal rx, qreal ry)
 
void drawEllipse (const QRect &rectangle)
 
void drawEllipse (const QRectF &rectangle)
 
void drawEllipse (int x, int y, int w, int h)
 
void drawGlyphRun (const QPointF &position, const QGlyphRun &glyphs)
 
void drawImage (const QPoint &point, const QImage &image)
 
void drawImage (const QPoint &point, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QPointF &point, const QImage &image)
 
void drawImage (const QPointF &point, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QRect &rectangle, const QImage &image)
 
void drawImage (const QRect &targetRect, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
void drawImage (const QRectF &rectangle, const QImage &image)
 
void drawImage (const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
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)
 
void drawLine (const QLine &line)
 
void drawLine (const QLineF &line)
 
void drawLine (const QPoint &p1, const QPoint &p2)
 
void drawLine (const QPointF &p1, const QPointF &p2)
 
void drawLine (int x1, int y1, int x2, int y2)
 
void drawLines (const QLine *lines, int lineCount)
 
void drawLines (const QLineF *lines, int lineCount)
 
void drawLines (const QPoint *pointPairs, int lineCount)
 
void drawLines (const QPointF *pointPairs, int lineCount)
 
void drawLines (const QVector< QLine > &lines)
 
void drawLines (const QVector< QLineF > &lines)
 
void drawLines (const QVector< QPoint > &pointPairs)
 
void drawLines (const QVector< QPointF > &pointPairs)
 
void drawPath (const QPainterPath &path)
 
void drawPicture (const QPoint &point, const QPicture &picture)
 
void drawPicture (const QPointF &point, const QPicture &picture)
 
void drawPicture (int x, int y, const QPicture &picture)
 
void drawPie (const QRect &rectangle, int startAngle, int spanAngle)
 
void drawPie (const QRectF &rectangle, int startAngle, int spanAngle)
 
void drawPie (int x, int y, int w, int h, int startAngle, int spanAngle)
 
void drawPixmap (const QPoint &point, const QPixmap &pixmap)
 
void drawPixmap (const QPoint &point, const QPixmap &pixmap, const QRect &sourceRect)
 
void drawPixmap (const QPointF &point, const QPixmap &pixmap)
 
void drawPixmap (const QPointF &point, const QPixmap &pixmap, const QRectF &sourceRect)
 
void drawPixmap (const QRect &rectangle, const QPixmap &pixmap)
 
void drawPixmap (const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect)
 
void drawPixmap (const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
 
void drawPixmap (int x, int y, const QPixmap &pixmap)
 
void drawPixmap (int x, int y, const QPixmap &pixmap, int sx, int sy, int sw, int sh)
 
void drawPixmap (int x, int y, int w, int h, const QPixmap &pixmap)
 
void drawPixmap (int x, int y, int w, int h, const QPixmap &pixmap, int sx, int sy, int sw, int sh)
 
void drawPixmapFragments (const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=PixmapFragmentHints ())
 
void drawPoint (const QPoint &point)
 
void drawPoint (const QPointF &point)
 
void drawPoint (int x, int y)
 
void drawPoints (const QPoint *points, int pointCount)
 
void drawPoints (const QPointF *points, int pointCount)
 
void drawPoints (const QPolygon &polygon)
 
void drawPoints (const QPolygonF &polygon)
 
void drawPolygon (const QPoint *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolygon (const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolygon (const QPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolygon (const QPolygonF &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)
 
void drawPolyline (const QPoint *points, int pointCount)
 
void drawPolyline (const QPointF *points, int pointCount)
 
void drawPolyline (const QPolygon &polygon)
 
void drawPolyline (const QPolygonF &polygon)
 
void drawRect (const QRect &rectangle)
 
void drawRect (const QRectF &rectangle)
 
void drawRect (int x, int y, int w, int h)
 
void drawRects (const QRect *rectangles, int rectCount)
 
void drawRects (const QRectF *rectangles, int rectCount)
 
void drawRects (const QVector< QRect > &rectangles)
 
void drawRects (const QVector< QRectF > &rectangles)
 
void drawRoundedRect (const QRect &rectangle, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 
void drawRoundedRect (const QRectF &rectangle, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 
void drawRoundedRect (int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 
void drawRoundRect (const QRect &rectangle, int xRound=25, int yRound=25)
 
void drawRoundRect (const QRectF &rectangle, int xRound=25, int yRound=25)
 
void drawRoundRect (int x, int y, int w, int h, int xRound=25, int yRound=25)
 
void drawStaticText (const QPoint &topLeftPosition, const QStaticText &staticText)
 
void drawStaticText (const QPointF &topLeftPosition, const QStaticText &staticText)
 
void drawStaticText (int left, int top, const QStaticText &staticText)
 
void drawText (const QPoint &point, const QString &text)
 
void drawText (const QPointF &position, const QString &text)
 
void drawText (const QRect &rectangle, int flags, const QString &text, QRect *boundingRect=nullptr)
 
void drawText (const QRectF &rectangle, const QString &text, const QTextOption &option=QTextOption ())
 
void drawText (const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect=nullptr)
 
void drawText (int x, int y, const QString &text)
 
void drawText (int x, int y, int w, int h, int flags, const QString &text, QRect *boundingRect=nullptr)
 
void drawTiledPixmap (const QRect &rectangle, const QPixmap &pixmap, const QPoint &position=QPoint ())
 
void drawTiledPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QPointF &position=QPointF ())
 
void drawTiledPixmap (int x, int y, int w, int h, const QPixmap &pixmap, int sx=0, int sy=0)
 
bool end ()
 
void endNativePainting ()
 
void eraseRect (const QRect &rectangle)
 
void eraseRect (const QRectF &rectangle)
 
void eraseRect (int x, int y, int w, int h)
 
void fillPath (const QPainterPath &path, const QBrush &brush)
 
void fillRect (const QRect &rectangle, const QBrush &brush)
 
void fillRect (const QRect &rectangle, const QColor &color)
 
void fillRect (const QRect &rectangle, Qt::BrushStyle style)
 
void fillRect (const QRect &rectangle, Qt::GlobalColor c)
 
void fillRect (const QRectF &rectangle, const QBrush &brush)
 
void fillRect (const QRectF &rectangle, const QColor &color)
 
void fillRect (const QRectF &rectangle, Qt::BrushStyle style)
 
void fillRect (const QRectF &rectangle, Qt::GlobalColor c)
 
void fillRect (int x, int y, int w, int h, const QBrush &brush)
 
void fillRect (int x, int y, int w, int h, const QColor &color)
 
void fillRect (int x, int y, int w, int h, Qt::BrushStyle style)
 
void fillRect (int x, int y, int w, int h, Qt::GlobalColor c)
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
bool hasClipping () const
 
void initFrom (const QPaintDevice *device)
 
bool isActive () const
 
Qt::LayoutDirection layoutDirection () const
 
const QMatrixmatrix () const
 
bool matrixEnabled () const
 
qreal opacity () const
 
QPaintEnginepaintEngine () const
 
const QPenpen () const
 
RenderHints renderHints () const
 
void resetMatrix ()
 
void resetTransform ()
 
void restore ()
 
void rotate (qreal angle)
 
void save ()
 
void scale (qreal sx, qreal sy)
 
void setBackground (const QBrush &brush)
 
void setBackgroundMode (Qt::BGMode mode)
 
void setBrush (const QBrush &brush)
 
void setBrush (Qt::BrushStyle style)
 
void setBrushOrigin (const QPoint &position)
 
void setBrushOrigin (const QPointF &position)
 
void setBrushOrigin (int x, int y)
 
void setClipPath (const QPainterPath &path, Qt::ClipOperation operation=Qt::ReplaceClip)
 
void setClipping (bool enable)
 
void setClipRect (const QRect &rectangle, Qt::ClipOperation operation=Qt::ReplaceClip)
 
void setClipRect (const QRectF &rectangle, Qt::ClipOperation operation=Qt::ReplaceClip)
 
void setClipRect (int x, int y, int w, int h, Qt::ClipOperation operation=Qt::ReplaceClip)
 
void setClipRegion (const QRegion &region, Qt::ClipOperation operation=Qt::ReplaceClip)
 
void setCompositionMode (CompositionMode mode)
 
void setFont (const QFont &font)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 
void setMatrixEnabled (bool enable)
 
void setOpacity (qreal opacity)
 
void setPen (const QColor &color)
 
void setPen (const QPen &pen)
 
void setPen (Qt::PenStyle style)
 
void setRenderHint (RenderHint hint, bool on=true)
 
void setRenderHints (RenderHints hints, bool on=true)
 
void setTransform (const QTransform &transform, bool combine=false)
 
void setViewport (const QRect &viewport)
 
void setViewport (int x, int y, int w, int h)
 
void setViewTransformEnabled (bool enable)
 
void setWindow (const QRect &window)
 
void setWindow (int x, int y, int w, int h)
 
void setWorldMatrix (const QMatrix &matrix, bool combine=false)
 
void setWorldMatrixEnabled (bool enable)
 
void setWorldTransform (const QTransform &matrix, bool combine=false)
 
void shear (qreal sh, qreal sv)
 
void strokePath (const QPainterPath &path, const QPen &pen)
 
bool testRenderHint (RenderHint hint) const
 
const QTransformtransform () const
 
void translate (const QPoint &offset)
 
void translate (const QPointF &offset)
 
void translate (qreal dx, qreal dy)
 
QRect viewport () const
 
bool viewTransformEnabled () const
 
QRect window () const
 
const QMatrixworldMatrix () const
 
bool worldMatrixEnabled () const
 
const QTransformworldTransform () const
 

Additional Inherited Members

- Public Typedefs inherited from QPainter
using PixmapFragmentHints = QFlags< PixmapFragmentHint >
 
using RenderHints = QFlags< RenderHint >
 
- Public Types inherited from QPainter
enum  CompositionMode
 
enum  PixmapFragmentHint
 
enum  RenderHint
 
- Static Public Methods inherited from QPainter
static QPaintDeviceredirected (const QPaintDevice *device, QPoint *position=nullptr)
 
static void restoreRedirected (const QPaintDevice *device)
 
static void setRedirected (const QPaintDevice *device, QPaintDevice *replacement, const QPoint &position=QPoint ())
 

Detailed Description

The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.

QStylePainter extends QPainter with a set of high-level draw...() functions implemented on top of QStyle's API. The advantage of using QStylePainter is that the parameter lists get considerably shorter. Whereas a QStyle object must be able to draw on any widget using any painter (because the application normally has one QStyle object shared by all widget), a QStylePainter is initialized with a widget, eliminating the need to specify the QWidget, the QPainter, and the QStyle for every function call.

Example using QStyle directly:

void MyWidget::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
}

Example using QStylePainter:

void MyWidget::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
See also
QStyle, QStyleOption

Constructor & Destructor Documentation

QStylePainter::QStylePainter ( )
inline

Constructs a QStylePainter.

QStylePainter::QStylePainter ( QWidget widget)
inlineexplicit

Construct a QStylePainter using widget widget for its paint device.

QStylePainter::QStylePainter ( QPaintDevice pd,
QWidget widget 
)
inline

Construct a QStylePainter using pd for its paint device, and attributes from widget.

Method Documentation

bool QStylePainter::begin ( QPaintDevice pd,
QWidget widget 
)
inline

Begin painting operations on paint device pd as if it was widget.

This is automatically called by the constructor that takes a QPaintDevice and a QWidget.

bool QStylePainter::begin ( QWidget widget)
inline

Begin painting operations on the specified widget. Returns true if the painter is ready to use, otherwise returns false.

This is automatically called by the constructor that takes a QWidget.

void QStylePainter::drawComplexControl ( QStyle::ComplexControl  cc,
const QStyleOptionComplex option 
)
inline

Use the widget's style to draw a complex control cc specified by the QStyleOptionComplex option.

See also
QStyle::drawComplexControl()
void QStylePainter::drawControl ( QStyle::ControlElement  ce,
const QStyleOption option 
)
inline

Use the widget's style to draw a control element ce specified by QStyleOption option.

See also
QStyle::drawControl()
void QStylePainter::drawItemPixmap ( const QRect rect,
int  flags,
const QPixmap pixmap 
)
inline

Draws the pixmap in rectangle rect. The pixmap is aligned according to flags.

See also
QStyle::drawItemPixmap(), Qt::Alignment>
void QStylePainter::drawItemText ( const QRect rect,
int  flags,
const QPalette pal,
bool  enabled,
const QString text,
QPalette::ColorRole  textRole = QPalette::NoRole 
)
inline

Draws the text in rectangle rect and palette pal. The text is aligned and wrapped according to flags.

The pen color is specified with textRole. The enabled bool indicates whether or not the item is enabled; when reimplementing this bool should influence how the item is drawn.

See also
QStyle::drawItemText(), Qt::Alignment>
void QStylePainter::drawPrimitive ( QStyle::PrimitiveElement  pe,
const QStyleOption option 
)
inline

Use the widget's style to draw a primitive element pe specified by QStyleOption option.

See also
QStyle::drawPrimitive()
QStyle * QStylePainter::style ( ) const
inline

Return the current style used by the QStylePainter.