QStylePainter Class Reference

[ QtGui module]

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

继承 QPainter .

方法


详细描述

QStylePainter 类是方便类用于绘制 QStyle 元素在 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 QPainter ,和 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);
 }
			

方法文档编制

QStylePainter.__init__ ( self )

构造 QStylePainter .

QStylePainter.__init__ ( self , QWidget   w )

构造 QStylePainter 使用 widget widget for its paint device.

QStylePainter.__init__ ( self , QPaintDevice   pd , QWidget   w )

构造 QStylePainter 使用 pd for its paint device, and attributes from widget .

bool QStylePainter.begin ( self , QWidget   w )

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 .

bool QStylePainter.begin ( self , QPaintDevice   pd , QWidget   w )

这是重载函数。

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

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

QStylePainter.drawComplexControl ( self , QStyle.ComplexControl   cc , QStyleOptionComplex   opt )

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

另请参阅 QStyle.drawComplexControl ().

QStylePainter.drawControl ( self , QStyle.ControlElement   ce , QStyleOption   opt )

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

另请参阅 QStyle.drawControl ().

QStylePainter.drawItemPixmap ( self , QRect   r , int  flags , QPixmap   pixmap )

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

另请参阅 QStyle.drawItemPixmap () 和 Qt.Alignment .

QStylePainter.drawItemText ( self , QRect   rect , int  flags , QPalette   pal , bool  enabled , QString  text , QPalette.ColorRole   textRole  = QPalette.NoRole)

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 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 .

QStylePainter.drawPrimitive ( self , QStyle.PrimitiveElement   pe , QStyleOption   opt )

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

另请参阅 QStyle.drawPrimitive ().

QStyle QStylePainter.style ( self )

Return the current style used by the QStylePainter .