PySide6.QtWidgets.QStylePainter¶
- class QStylePainter¶
- The - QStylePainterclass is a convenience class for drawing- QStyleelements inside a widget. More…- Synopsis¶- Methods¶- def - __init__()
- def - begin()
- def - drawControl()
- def - drawItemPixmap()
- def - drawItemText()
- def - drawPrimitive()
- def - style()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - QStylePainterextends QPainter with a set of high-level- draw...()functions implemented on top of- QStyle‘s API. The advantage of using- QStylePainteris that the parameter lists get considerably shorter. Whereas a- QStyleobject must be able to draw on any widget using any painter (because the application normally has one- QStyleobject shared by all widget), a- QStylePainteris initialized with a widget, eliminating the need to specify the- QWidget, the QPainter, and the- QStylefor every function call.- Example using - QStyledirectly:- 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) - Example using - QStylePainter:- def paintEvent(self, */): painter = QStylePainter(self) option = QStyleOptionFocusRect() option.initFrom(self) option.backgroundColor = palette().color(QPalette.Background) painter.drawPrimitive(QStyle.PE_FrameFocusRect, option) - See also - __init__()¶
 - Constructs a - QStylePainter.- __init__(w)
- Parameters:
- w – - QWidget
 
 - Construct a - QStylePainterusing widget- widgetfor its paint device.- __init__(pd, w)
- Parameters:
- pd – - QPaintDevice
- w – - QWidget
 
 
 - Construct a - QStylePainterusing- pdfor its paint device, and attributes from- widget.- Begin painting operations on the specified - widget. Returns- trueif the painter is ready to use; otherwise returns- false.- This is automatically called by the constructor that takes a - QWidget.- begin(pd, w)
- Parameters:
- pd – - QPaintDevice
- w – - QWidget
 
- Return type:
- bool 
 
 - This is an overloaded function. - Begin painting operations on paint device - pdas if it was- widget.- This is automatically called by the constructor that takes a QPaintDevice and a - QWidget.- drawComplexControl(cc, opt)¶
- Parameters:
- cc – - ComplexControl
- opt – - QStyleOptionComplex
 
 
 - Use the widget’s style to draw a complex control - ccspecified by the- QStyleOptionComplex- option.- See also - drawControl(ce, opt)¶
- Parameters:
- ce – - ControlElement
- opt – - QStyleOption
 
 
 - Use the widget’s style to draw a control element - cespecified by- QStyleOption- option.- See also - Draws the - pixmapin rectangle- rect. The pixmap is aligned according to- flags.- See also - drawItemPixmap()- Alignment- drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])¶
 - Draws the - textin rectangle- rectand palette- pal. The text is aligned and wrapped according to- flags.- The pen color is specified with - textRole. The- enabledbool indicates whether or not the item is enabled; when reimplementing this bool should influence how the item is drawn.- See also - drawItemText()- Alignment- drawPrimitive(pe, opt)¶
- Parameters:
- pe – - PrimitiveElement
- opt – - QStyleOption
 
 
 - Use the widget’s style to draw a primitive element - pespecified by- QStyleOption- option.- See also - Return the current style used by the - QStylePainter.