- class QStylePainter#
The
QStylePainter
class is a convenience class for drawingQStyle
elements 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.
QStylePainter
extends QPainter with a set of high-leveldraw...()
functions implemented on top ofQStyle
‘s API. The advantage of usingQStylePainter
is that the parameter lists get considerably shorter. Whereas aQStyle
object must be able to draw on any widget using any painter (because the application normally has oneQStyle
object shared by all widget), aQStylePainter
is initialized with a widget, eliminating the need to specify theQWidget
, the QPainter, and theQStyle
for every function call.Example using
QStyle
directly: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__(pd, w)
- Parameters:
pd –
QPaintDevice
w –
QWidget
Construct a
QStylePainter
usingpd
for its paint device, and attributes fromwidget
.- __init__(w)
- Parameters:
w –
QWidget
Construct a
QStylePainter
using widgetwidget
for its paint device.- begin(pd, w)#
- Parameters:
pd –
QPaintDevice
w –
QWidget
- Return type:
bool
This is an overloaded function.
Begin painting operations on paint device
pd
as if it waswidget
.This is automatically called by the constructor that takes a QPaintDevice and a
QWidget
.- begin(w)
- Parameters:
w –
QWidget
- Return type:
bool
Begin painting operations on the specified
widget
. Returnstrue
if the painter is ready to use; otherwise returnsfalse
.This is automatically called by the constructor that takes a
QWidget
.- drawComplexControl(cc, opt)#
- Parameters:
cc –
ComplexControl
opt –
QStyleOptionComplex
Use the widget’s style to draw a complex control
cc
specified by theQStyleOptionComplex
option
.See also
- drawControl(ce, opt)#
- Parameters:
ce –
ControlElement
opt –
QStyleOption
Use the widget’s style to draw a control element
ce
specified byQStyleOption
option
.See also
Draws the
pixmap
in rectanglerect
. The pixmap is aligned according toflags
.See also
drawItemPixmap()
Alignment
- drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])#
Draws the
text
in rectanglerect
and palettepal
. The text is aligned and wrapped according toflags
.The pen color is specified with
textRole
. Theenabled
bool 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
pe
specified byQStyleOption
option
.See also
Return the current style used by the
QStylePainter
.