内容表

上一话题

QStyleOptionViewItem

下一话题

QStyledItemDelegate

QStylePainter

QStylePainter class is a convenience class for drawing QStyle 元素在 Widget 内。 更多

Inheritance diagram of PySide2.QtWidgets.QStylePainter

概要

函数

详细描述

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:

def paintEvent(self, event):
    painter = QPainter(self)
    option = QStyleOptionFocusRect()
    option.initFrom(self)
    option.backgroundColor = palette().color(QPalette.Background)
    style().drawPrimitive(QStyle.PE_FrameFocusRect, option, painter, self)
											

Example using QStylePainter :

def paintEvent(self, event):
{
    painter = QStylePainter(self)
    option = QStyleOptionFocusRect()
    option.initFrom(self)
    option.backgroundColor = palette().color(QPalette.Background)
    painter.drawPrimitive(QStyle.PE_FrameFocusRect, option)
											
class QStylePainter

QStylePainter(pd, w)

QStylePainter(w)

param w

QWidget

param pd

QPaintDevice

构造 QStylePainter .

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

构造 QStylePainter using widget widget for its paint device.

PySide2.QtWidgets.QStylePainter. begin ( pd , w )
参数
返回类型

bool

这是重载函数。

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

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

PySide2.QtWidgets.QStylePainter. begin ( w )
参数

w QWidget

返回类型

bool

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 .

PySide2.QtWidgets.QStylePainter. drawComplexControl ( cc , opt )
参数

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

PySide2.QtWidgets.QStylePainter. drawControl ( ce , opt )
参数

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

另请参阅

drawControl()

PySide2.QtWidgets.QStylePainter. drawItemPixmap ( r , flags , pixmap )
参数
  • r QRect

  • flags int

  • pixmap QPixmap

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

另请参阅

drawItemPixmap() Alignment

PySide2.QtWidgets.QStylePainter. drawItemText ( r , flags , pal , enabled , text [ , textRole=QPalette.NoRole ] )
参数
  • r QRect

  • flags int

  • pal QPalette

  • enabled bool

  • text – unicode

  • textRole ColorRole

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.

另请参阅

drawItemText() Alignment

PySide2.QtWidgets.QStylePainter. drawPrimitive ( pe , opt )
参数

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

另请参阅

drawPrimitive()

PySide2.QtWidgets.QStylePainter. style ( )
返回类型

QStyle

Return the current style used by the QStylePainter .