QStylePainter¶
The
QStylePainter
class is a convenience class for drawingQStyle
elements 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¶
QStylePainter
extendsQPainter
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
, theQPainter
, and theQStyle
for every function call.Example using
QStyle
directly: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
QStylePainter
usingpd
for its paint device, and attributes fromwidget
.Construct a
QStylePainter
using widgetwidget
for its paint device.
- PySide2.QtWidgets.QStylePainter.begin(pd, w)¶
- Parameters:
- 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 aQWidget
.
- PySide2.QtWidgets.QStylePainter.begin(w)
- Parameters:
- 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
.
- PySide2.QtWidgets.QStylePainter.drawComplexControl(cc, opt)¶
- Parameters:
Use the widget’s style to draw a complex control
cc
specified by theQStyleOptionComplex
option
.See also
- PySide2.QtWidgets.QStylePainter.drawControl(ce, opt)¶
- Parameters:
ce –
ControlElement
Use the widget’s style to draw a control element
ce
specified byQStyleOption
option
.See also
- PySide2.QtWidgets.QStylePainter.drawItemPixmap(r, flags, pixmap)¶
- Parameters:
flags – int
pixmap –
PySide2.QtGui.QPixmap
Draws the
pixmap
in rectanglerect
. The pixmap is aligned according toflags
.See also
drawItemPixmap()
Alignment
- PySide2.QtWidgets.QStylePainter.drawItemText(r, flags, pal, enabled, text[, textRole=QPalette.NoRole])¶
- Parameters:
flags – int
pal –
PySide2.QtGui.QPalette
enabled – bool
text – str
textRole –
ColorRole
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
- PySide2.QtWidgets.QStylePainter.drawPrimitive(pe, opt)¶
- Parameters:
pe –
PrimitiveElement
Use the widget’s style to draw a primitive element
pe
specified byQStyleOption
option
.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.