QStylePainter 类

QStylePainter 类是方便类用于绘制 QStyle 元素在 Widget 内。 更多...

头: #include <QStylePainter>
qmake: QT += widgets
继承: QPainter

公共函数

QStylePainter (QPaintDevice * pd , QWidget * widget )
QStylePainter (QWidget * widget )
QStylePainter ()
bool begin (QWidget * widget )
bool begin (QPaintDevice * pd , QWidget * widget )
void drawComplexControl (QStyle::ComplexControl cc , const QStyleOptionComplex & option )
void drawControl (QStyle::ControlElement ce , const QStyleOption & option )
void drawItemPixmap (const QRect & rect , int flags , const QPixmap & pixmap )
void drawItemText (const QRect & rect , int flags , const QPalette & pal , bool enabled , const QString & text , QPalette::ColorRole textRole = QPalette::NoRole)
void drawPrimitive (QStyle::PrimitiveElement pe , const QStyleOption & option )
QStyle * style () const

详细描述

QStylePainter 延伸 QPainter 采用一组高级 draw...() 函数实现在顶部基于 QStyle 的 API。使用 QStylePainter 的优点是参数列表会变得相当短。而 QStyle 对象能够在任何 Widget 中绘制必须使用任何描绘器 (因为应用程序通常有一 QStyle 对象由所有 Widget 共享),QStylePainter 采用 Widget 初始化,无需指定 QWidget QPainter ,和 QStyle 对于每个函数调用。

范例使用 QStyle 直接:

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

范例使用 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);
}
					

另请参阅 QStyle and QStyleOption .

成员函数文档编制

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

构造 QStylePainter 使用 pd 对于其描绘设备,且属性来自 widget .

QStylePainter:: QStylePainter ( QWidget * widget )

构造 QStylePainter 使用小部件 widget 对于其描绘设备。

QStylePainter:: QStylePainter ()

构造 QStylePainter。

bool QStylePainter:: begin ( QWidget * widget )

Begin painting operations on the specified widget 。返回 true if the painter is ready to use; otherwise returns false .

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

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

这是重载函数。

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

This is automatically called by the constructor that takes a QPaintDevice 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 .

另请参阅 QStyle::drawComplexControl ().

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

Use the widget's style to draw a control element ce 指定通过 QStyleOption option .

另请参阅 QStyle::drawControl ().

void QStylePainter:: drawItemPixmap (const QRect & rect , int flags , const QPixmap & pixmap )

绘制 pixmap in rectangle rect . The pixmap is aligned according to flags .

另请参阅 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)

绘制 text in rectangle rect and palette pal . The text is aligned and wrapped according to flags .

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

另请参阅 QStyle::drawItemText () 和 Qt::Alignment .

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

Use the widget's style to draw a primitive element pe 指定通过 QStyleOption option .

另请参阅 QStyle::drawPrimitive ().

QStyle *QStylePainter:: style () const

Return the current style used by the QStylePainter .