QStylePainter¶
The
QStylePainterclass is a convenience class for drawingQStyleelements inside a widget. More…

Synopsis¶
Functions¶
def
begin(pd, w)def
begin(w)def
drawComplexControl(cc, opt)def
drawControl(ce, opt)def
drawItemPixmap(r, flags, pixmap)def
drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])def
drawPrimitive(pe, opt)def
style()
Detailed Description¶
QStylePainterextendsQPainterwith a set of high-leveldraw...()functions implemented on top ofQStyle‘s API. The advantage of usingQStylePainteris that the parameter lists get considerably shorter. Whereas aQStyleobject must be able to draw on any widget using any painter (because the application normally has oneQStyleobject shared by all widget), aQStylePainteris initialized with a widget, eliminating the need to specify theQWidget, theQPainter, and theQStylefor every function call.Example using
QStyledirectly: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)See also
- class PySide2.QtWidgets.QStylePainter¶
PySide2.QtWidgets.QStylePainter(pd, w)
PySide2.QtWidgets.QStylePainter(w)
- param w:
- param pd:
Constructs a
QStylePainter.Construct a
QStylePainterusingpdfor its paint device, and attributes fromwidget.Construct a
QStylePainterusing widgetwidgetfor its paint device.
- PySide2.QtWidgets.QStylePainter.begin(pd, w)¶
- Parameters:
pd –
PySide2.QtGui.QPaintDevice
- Return type:
bool
This is an overloaded function.
Begin painting operations on paint device
pdas if it waswidget.This is automatically called by the constructor that takes a
QPaintDeviceand aQWidget.
- PySide2.QtWidgets.QStylePainter.begin(w)
- Parameters:
- Return type:
bool
Begin painting operations on the specified
widget. Returnstrueif the painter is ready to use; otherwise returnsfalse.This is automatically called by the constructor that takes a
QWidget.
- PySide2.QtWidgets.QStylePainter.drawComplexControl(cc, opt)¶
- Parameters:
cc –
ComplexControl
Use the widget’s style to draw a complex control
ccspecified by theQStyleOptionComplexoption.See also
- PySide2.QtWidgets.QStylePainter.drawControl(ce, opt)¶
- Parameters:
ce –
ControlElementopt –
PySide2.QtWidgets.QStyleOption
Use the widget’s style to draw a control element
cespecified byQStyleOptionoption.See also
- PySide2.QtWidgets.QStylePainter.drawItemPixmap(r, flags, pixmap)¶
- Parameters:
r –
PySide2.QtCore.QRectflags – int
pixmap –
PySide2.QtGui.QPixmap
Draws the
pixmapin rectanglerect. The pixmap is aligned according toflags.See also
drawItemPixmap()Alignment
- PySide2.QtWidgets.QStylePainter.drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])¶
- Parameters:
r –
PySide2.QtCore.QRectflags – int
pal –
PySide2.QtGui.QPaletteenabled – bool
text – str
textRole –
ColorRole
Draws the
textin rectanglerectand palettepal. The text is aligned and wrapped according toflags.The pen color is specified with
textRole. Theenabledbool indicates whether or not the item is enabled; when reimplementing this bool should influence how the item is drawn.See also
drawItemText()Alignment
- PySide2.QtWidgets.QStylePainter.drawPrimitive(pe, opt)¶
- Parameters:
pe –
PrimitiveElementopt –
PySide2.QtWidgets.QStyleOption
Use the widget’s style to draw a primitive element
pespecified byQStyleOptionoption.See also
- PySide2.QtWidgets.QStylePainter.style()¶
- Return type:
Return the current style used by the
QStylePainter.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.