- class QStylePainter#
QStylePainter类是一个方便的类,用于在控件内绘制
QStyle元素。 更多...概要#
方法#
def
__init__()def
begin()def
drawControl()def
drawItemPixmap()def
drawItemText()def
drawPrimitive()def
style()
注意
此文档可能包含自动从C++翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译有问题,您也可以通过在https:/bugreports.qt.io/projects/PYSIDE上创建问题来解决。
详细描述#
警告
本部分包含从C++自动翻译到Python的代码片段,可能包含错误。
QStylePainter继承自QPainter,并包含一系列基于QStyleAPI实现的draw...()高级函数。使用QStylePainter的优势在于参数列表显著缩短。而在使用QStyle对象时,必须能够使用任何画家在任何小部件上绘制(因为应用程序通常有一个由所有小部件共享的QStyle对象),而QStylePainter则使用小部件初始化,消除了在每次函数调用时指定QWidget、QPainter和QStyle的需要。直接使用
QStyle的示例def paintEvent(self, */): painter = QPainter(self) option = QStyleOptionFocusRect() option.initFrom(self) option.backgroundColor = palette().color(QPalette.Background) style().drawPrimitive(QStyle.PE_FrameFocusRect, option, painter, self)
使用
QStylePainter的示例def paintEvent(self, */): painter = QStylePainter(self) option = QStyleOptionFocusRect() option.initFrom(self) option.backgroundColor = palette().color(QPalette.Background) painter.drawPrimitive(QStyle.PE_FrameFocusRect, option)
另请参阅
- __init__()#
构造一个
QStylePainter。- __init__(pd, w)
- 参数:
pd –
QPaintDevicew –
QWidget
使用代码为画布设备的
pd和代码的属性构建QStylePainter。- __init__(w)
- 参数:
w –
QWidget
使用小部件
widget作为其画布设备的QStylePainter。- begin(pd, w)#
- 参数:
pd –
QPaintDevicew –
QWidget
- 返回类型:
布尔型
这是一个重载函数。
开始对绘画设备
pd进行绘制操作,就像是在绘制widget一样。此函数在带有 QPaintDevice 和
QWidget的构造函数中自动调用。- begin(w)
- 参数:
w –
QWidget- 返回类型:
布尔型
开始对指定的
widget进行绘制操作。如果绘制器准备就绪则返回true,否则返回false。此函数在带有
QWidget的构造函数中自动调用。- drawComplexControl(cc, opt)#
- 参数:
cc –
ComplexControlopt –
QStyleOptionComplex
使用小部件的样式绘制根据
QStyleOptionComplexoption指定的复杂控件cc。另请参阅
- drawControl(ce, opt)#
- 参数:
ce –
ControlElementopt –
QStyleOption
使用小部件的样式绘制根据
QStyleOptionoption指定的控件元素ce。另请参阅
将
pixmap绘制到矩形区域rect。图像的对齐方式根据flags进行。另请参阅
drawItemPixmap()Alignment- drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])#
在矩形区域
rect和调色板pal中绘制text。文本的对齐和换行根据flags进行。用
textRole来指定画笔颜色。布尔型的enabled表示项目是否启用;在重写时,这个布尔型应该影响项目的绘制方式。另请参阅
drawItemText()Alignment- drawPrimitive(pe, opt)#
- 参数:
pe –
PrimitiveElementopt –
QStyleOption
使用小部件的样式绘制由
QStyleOptionoption指定的原语元素pe。另请参阅
返回
QStylePainter当前使用的样式。