Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QStylePainter Class Reference

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

    #include <QStylePainter>

Inherits QPainter.

- List of all members, including inherited members

### Public Functions

- QStylePainter ()
- QStylePainter ( QWidget * widget )
- QStylePainter ( QPaintDevice * pd, QWidget * widget )
- bool begin ( QWidget * widget )
- bool begin ( QPaintDevice * pd, QWidget * widget )
- void drawComplexControl ( QStyle::ComplexControl cc, const QStyleOptionComplex & option )
- void drawComplexControlMask ( QStyle::ComplexControl cc, const QStyleOptionComplex & option )
- void drawControl ( QStyle::ControlElement ce, const QStyleOption & option )
- void drawControlMask ( QStyle::ControlElement element, const QStyleOption & option )
- void drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QString & text, int len = -1, const QColor * penColor = 0 )
- void drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QPixmap & pixmap, const QColor * penColor = 0 )
- void drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QPixmap & pixmap, const QString & text, int len = -1, const QColor * penColor = 0 )
- void drawPrimitive ( QStyle::PrimitiveElement pe, const QStyleOption & option )
- QStyle * style () const

- 140 public functions inherited from QPainter

## 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);

            QStyleOptionFocusRect option;
            option.init(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);

            QStyleOptionFocusRect option;
            option.init(this);
            option.backgroundColor = palette().color(QPalette::Background);

            painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
        }

See also QStyle and QStyleOption.

## Member Function Documentation

### QStylePainter::QStylePainter ()

Constructs a QStylePainter.

### QStylePainter::QStylePainter ( QWidget * widget )

Construct a QStylePainter using widget widget for its paint device.

### QStylePainter::QStylePainter ( QPaintDevice * pd, QWidget * widget )

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

### bool QStylePainter::begin ( QWidget * widget )

Begin painting operations on widget widget. This is automatically called by the constructor that takes a QWidget.

### bool QStylePainter::begin ( QPaintDevice * pd, QWidget * widget )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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.

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

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

See also QStyle::drawComplexControl().

### void QStylePainter::drawComplexControlMask ( QStyle::ComplexControl cc, const QStyleOptionComplex & option )

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

See also QStyle::drawComplexControlMask().

### void QStylePainter::drawControl ( QStyle::ControlElement ce, const QStyleOption & option )

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

See also QStyle::drawControl().

### void QStylePainter::drawControlMask ( QStyle::ControlElement element, const QStyleOption & option )

Use the widget's style to draw the mast for control element element further specified by QStyleOption option.

See also QStyle::drawControlMask().

### void QStylePainter::drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QString & text, int len = -1, const QColor * penColor = 0 )

Draws the text in rectangle rect and palette pal.

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

If len is -1 (the default), all the text is drawn; otherwise only the first len characters of text are drawn. The text is aligned and wrapped according to flags.

See also QStyle::drawItem() and Qt::Alignment.

### void QStylePainter::drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QPixmap & pixmap, const QColor * penColor = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Draws the pixmap in rectangle rect using palette pal.

See also QStyle::drawItem().

### void QStylePainter::drawItem ( const QRect & rect, int flags, const QPalette & pal, bool enabled, const QPixmap & pixmap, const QString & text, int len = -1, const QColor * penColor = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Draws the pixmap or text in rectangle rect using palette pal.

See also QStyle::drawItem().

### void QStylePainter::drawPrimitive ( QStyle::PrimitiveElement pe, const QStyleOption & option )

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

See also QStyle::drawPrimitive().

### QStyle * QStylePainter::style () const

Return the current style used by the QStylePainter.