PySide6.QtWidgets.QStylePainter¶
- class QStylePainter¶
The
QStylePainterclass is a convenience class for drawingQStyleelements inside a widget.Details
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QStylePainterextends QPainter with 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, the QPainter, and theQStylefor every function call.Example using
QStyledirectly:def paintEvent(self, */): //! [0] //! [2] painter = QPainter(self) //! [2] option = QStyleOptionFocusRect() option.initFrom(self) option.backgroundColor = palette().color(QPalette.Background) //! [3] style().drawPrimitive(QStyle.PE_FrameFocusRect, option, painter, self) //! [3]Example using
QStylePainter:def paintEvent(self, */): painter = QStylePainter(self) //! [5] option = QStyleOptionFocusRect() option.initFrom(self) option.backgroundColor = palette().color(QPalette.Background) //! [7] painter.drawPrimitive(QStyle.PE_FrameFocusRect, option) //! [7]See also
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
- __init__()¶
Constructs a
QStylePainter.- __init__(w)
- Parameters:
w –
QWidget
Construct a
QStylePainterusing widgetwidgetfor its paint device.- __init__(pd, w)
- Parameters:
pd –
QPaintDevicew –
QWidget
Construct a
QStylePainterusingpdfor its paint device, and attributes fromwidget.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.- begin(pd, w)
- Parameters:
pd –
QPaintDevicew –
QWidget
- Return type:
bool
Begin painting operations on paint device
pdas if it waswidget.This is automatically called by the constructor that takes a QPaintDevice and a
QWidget.- drawComplexControl(cc, opt)¶
- Parameters:
cc –
ComplexControlopt –
QStyleOptionComplex
Use the widget’s style to draw a complex control
ccspecified by theQStyleOptionComplexoption.See also
- drawControl(ce, opt)¶
- Parameters:
ce –
ControlElementopt –
QStyleOption
Use the widget’s style to draw a control element
cespecified byQStyleOptionoption.See also
Draws the
pixmapin rectanglerect. The pixmap is aligned according toflags.See also
drawItemPixmap()Alignment- drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])¶
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- drawPrimitive(pe, opt)¶
- Parameters:
pe –
PrimitiveElementopt –
QStyleOption
Use the widget’s style to draw a primitive element
pespecified byQStyleOptionoption.See also
Return the current style used by the
QStylePainter.