QStylePainter Class
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget. More...
Header: | #include <QStylePainter> |
qmake: | QT += widgets |
Inherits: | QPainter |
Public Functions
QStylePainter() | |
QStylePainter(QWidget *w) | |
QStylePainter(QPaintDevice *pd, QWidget *w) | |
bool | begin(QWidget *w) |
bool | begin(QPaintDevice *pd, QWidget *w) |
void | drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt) |
void | drawControl(QStyle::ControlElement ce, const QStyleOption &opt) |
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 &opt) |
QStyle * | style() const |
- 193 public functions inherited from QPainter
Additional Inherited Members
- 1 public variable 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.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); QStyleOptionFocusRect option; option.initFrom(this); option.backgroundColor = palette().color(QPalette::Background); painter.drawPrimitive(QStyle::PE_FrameFocusRect, option); }
See also QStyle and QStyleOption.
Member Function Documentation
QStylePainter::QStylePainter()
Default constructs an instance of QStylePainter.
QStylePainter::QStylePainter(QWidget *w)
Default constructs an instance of QStylePainter.
QStylePainter::QStylePainter(QPaintDevice *pd, QWidget *w)
Default constructs an instance of QStylePainter.