KDE 4.9 PyKDE API Reference

- KDE's Python API

# KStyle Class Reference

`from PyKDE4.kdeui import *`

Inherits: QStyle → QObject

## Detailed Description

Makes style coding more convenient.

To do: and allows to style KDE specific widgets.

KStyle strives to ease style development by implementing various QStyle methods. These implementations are based on

1. the concept of Layout Properties. These properties can be set using setWidgetLayoutProp(). KStyle uses this information to respect various metrics (like space between primitives or margins around widget contents) or turn specific features on or off.
2. the concept of KStyle Primitives. These can be implemented by overriding drawKStylePrimitive() and providing drawing methods for specific primitives. Often, the drawing of more complex widgets consists of several primitives.

In the following modules, information about related members is collected: - OptionGroup - WidgetGroup

Author:
  Maksim Orlovich (maksim\@kde.org)

Author:
  Sandro Giessl (giessl\@kde.org)

See also:
  KStyleFactory for how to implement the style plugin interface.

## Enumerations

MarginOffsets | { MainMargin, Top, Bot, Left, Right, MarginInc }
WidgetType | { WT_Generic, WT_PushButton, WT_Splitter, WT_CheckBox, WT_RadioButton, WT_DockWidget, WT_ProgressBar, WT_MenuBar, WT_MenuBarItem, WT_Menu, WT_MenuItem, WT_ScrollBar, WT_TabBar, WT_TabWidget, WT_Slider, WT_Tree, WT_SpinBox, WT_ComboBox, WT_Header, WT_LineEdit, WT_GroupBox, WT_StatusBar, WT_ToolBar, WT_ToolButton, WT_ToolBoxTab, WT_Window, WT_Limit }

## Methods

| __init__ (self)
QRect | centerRect (self, QRect in, int w, int h)
QRect | centerRect (self, QRect in, QSize size)
| drawComplexControl (self, QStyle::ComplexControl cc, QStyleOptionComplex opt, QPainter p, QWidget w)
| drawControl (self, QStyle::ControlElement elem, QStyleOption opt, QPainter p, QWidget w)
| drawInsideRect (self, QPainter p, QRect r)
| drawItemPixmap (self, QPainter painter, QRect rect, int alignment, QPixmap pixmap)
| drawItemText (self, QPainter painter, QRect rect, int flags, QPalette pal, bool enabled, QString text, QPalette::ColorRole textRole=QPalette.NoRole)
| drawPrimitive (self, QStyle::PrimitiveElement elem, QStyleOption opt, QPainter p, QWidget w)
bool | eventFilter (self, QObject a0, QEvent a1)
QPixmap | generatedIconPixmap (self, QIcon::Mode iconMode, QPixmap pixmap, QStyleOption opt)
QStyle::SubControl | hitTestComplexControl (self, QStyle::ComplexControl cc, QStyleOptionComplex opt, QPoint pt, QWidget w)
QRect | itemPixmapRect (self, QRect r, int flags, QPixmap pixmap)
QRect | itemTextRect (self, QFontMetrics fm, QRect r, int flags, bool enabled, QString text)
int | layoutSpacingImplementation (self, QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, QStyleOption option, QWidget widget)
QStyle::ControlElement | newControlElement (self, QString element)
QStyle::StyleHint | newStyleHint (self, QString element)
QStyle::SubElement | newSubElement (self, QString element)
int | pixelMetric (self, QStyle::PixelMetric metric, QStyleOption opt=0, QWidget w=0)
| polish (self, QWidget a0)
| polish (self, QApplication a0)
| polish (self, QPalette a0)
| setWidgetLayoutProp (self, KStyle.WidgetType widget, int metric, int value)
QSize | sizeFromContents (self, QStyle::ContentsType type, QStyleOption opt, QSize contentsSize, QWidget w)
QIcon | standardIconImplementation (self, QStyle::StandardPixmap standardIcon, QStyleOption option=0, QWidget widget=0)
QPalette | standardPalette (self)
QPixmap | standardPixmap (self, QStyle::StandardPixmap standardPixmap, QStyleOption opt, QWidget widget=0)
int | styleHint (self, QStyle::StyleHint hint, QStyleOption opt, QWidget w, QStyleHintReturn returnData)
QRect | subControlRect (self, QStyle::ComplexControl control, QStyleOptionComplex opt, QStyle::SubControl subControl, QWidget w)
QRect | subElementRect (self, QStyle::SubElement subRect, QStyleOption opt, QWidget w)
| unpolish (self, QWidget a0)
| unpolish (self, QApplication a0)
int | widgetLayoutProp (self, KStyle.WidgetType widgetType, int metric, QStyleOption opt=0, QWidget w=0)

## Static Methods

QStyle::ControlElement | customControlElement (QString element, QWidget widget)
QStyle::StyleHint | customStyleHint (QString element, QWidget widget)
QStyle::SubElement | customSubElement (QString element, QWidget widget)
QString | defaultStyle ()

## Method Documentation

__init__ | ( |  | self ) |

QRect centerRect | ( | self, |
|  | QRect | in,
|  | int | w,
|  | int | h
| ) |  |  |

Return a size-dimension QRect centered inside the 'in' rectangle

QRect centerRect | ( | self, |
|  | QRect | in,
|  | QSize | size
| ) |  |  |

Return a size-dimension QRect centered inside the 'in' rectangle

drawComplexControl | ( | self, |
|  | QStyle::ComplexControl | cc,
|  | QStyleOptionComplex | opt,
|  | QPainter | p,
|  | QWidget | w
| ) |  |  |

drawControl | ( | self, |
|  | QStyle::ControlElement | elem,
|  | QStyleOption | opt,
|  | QPainter | p,
|  | QWidget | w
| ) |  |  |

QStyle Methods These are methods reimplemented from QStyle. Usually it's not necessary to reimplement them yourself.

Some of them are there for binary compatibility reasons only; all they do is to call the implementation from QCommonStyle.

drawInsideRect | ( | self, |
|  | QPainter | p,
|  | QRect | r
| ) |  |  |

Draws inside the rectangle using a thinkness 0 pen. This is what drawRect in Qt3 used to do.

drawItemPixmap | ( | self, |
|  | QPainter | painter,
|  | QRect | rect,
|  | int | alignment,
|  | QPixmap | pixmap
| ) |  |  |

drawItemText | ( | self, |
|  | QPainter | painter,
|  | QRect | rect,
|  | int | flags,
|  | QPalette | pal,
|  | bool | enabled,
|  | QString | text,
|  | QPalette::ColorRole | textRole=QPalette.NoRole
| ) |  |  |

drawPrimitive | ( | self, |
|  | QStyle::PrimitiveElement | elem,
|  | QStyleOption | opt,
|  | QPainter | p,
|  | QWidget | w
| ) |  |  |

bool eventFilter | ( | self, |
|  | QObject | a0,
|  | QEvent | a1
| ) |  |  |

QPixmap generatedIconPixmap | ( | self, |
|  | QIcon::Mode | iconMode,
|  | QPixmap | pixmap,
|  | QStyleOption | opt
| ) |  |  |

QStyle::SubControl hitTestComplexControl | ( | self, |
|  | QStyle::ComplexControl | cc,
|  | QStyleOptionComplex | opt,
|  | QPoint | pt,
|  | QWidget | w
| ) |  |  |

QRect itemPixmapRect | ( | self, |
|  | QRect | r,
|  | int | flags,
|  | QPixmap | pixmap
| ) |  |  |

QRect itemTextRect | ( | self, |
|  | QFontMetrics | fm,
|  | QRect | r,
|  | int | flags,
|  | bool | enabled,
|  | QString | text
| ) |  |  |

int layoutSpacingImplementation | ( | self, |
|  | QSizePolicy::ControlType | control1,
|  | QSizePolicy::ControlType | control2,
|  | Qt::Orientation | orientation,
|  | QStyleOption | option,
|  | QWidget | widget
| ) |  |  |

QStyle::ControlElement newControlElement | ( | self, |
|  | QString | element
| ) |  |  |

QStyle::StyleHint newStyleHint | ( | self, |
|  | QString | element
| ) |  |  |

Runtime element extension, allows inheriting styles to add support custom elements merges supporting inherit chains Supposed to be called e.g. in your constructor.

NOTICE: in order to have this work, your style must provide an "X-KDE-CustomElements" classinfo, i.e. class MyStyle : public KStyle { Q_OBJECT Q_CLASSINFO ("X-KDE-CustomElements", "true")

public: ..... }

Parameters:

  | element | The style element, represented as string. Suggested naming convention: appname.(2-char-element-type)_element where the 2-char-element-type is of {SH, CE, SE} widgets in kdelibs don't have to pass the appname examples: "CE_CapacityBar", "amarok.CE_Analyzer"

Important notes: 1) If your string lacks the matching "SH_", "CE_" or "SE_" token the element request will be ignored (return is 0) 2) To keep UI coherency, don't support any nonsense in your style, but convince app developers to use standard elements - if available

QStyle::SubElement newSubElement | ( | self, |
|  | QString | element
| ) |  |  |

int pixelMetric | ( | self, |
|  | QStyle::PixelMetric | metric,
|  | QStyleOption | opt=0,
|  | QWidget | w=0
| ) |  |  |

polish | ( | self, |
|  | QWidget | a0
| ) |  |  |

polish | ( | self, |
|  | QApplication | a0
| ) |  |  |

polish | ( | self, |
|  | QPalette | a0
| ) |  |  |

setWidgetLayoutProp | ( | self, |
|  | KStyle.WidgetType | widget,
|  | int | metric,
|  | int | value
| ) |  |  |

Describes windows, like in QWorkspace.

To do: SP_TitleBar* pixmaps

@sa WT_Window

QSize sizeFromContents | ( | self, |
|  | QStyle::ContentsType | type,
|  | QStyleOption | opt,
|  | QSize | contentsSize,
|  | QWidget | w
| ) |  |  |

QIcon standardIconImplementation | ( | self, |
|  | QStyle::StandardPixmap | standardIcon,
|  | QStyleOption | option=0,
|  | QWidget | widget=0
| ) |  |  |

QPalette standardPalette | ( |  | self ) |

QPixmap standardPixmap | ( | self, |
|  | QStyle::StandardPixmap | standardPixmap,
|  | QStyleOption | opt,
|  | QWidget | widget=0
| ) |  |  |

int styleHint | ( | self, |
|  | QStyle::StyleHint | hint,
|  | QStyleOption | opt,
|  | QWidget | w,
|  | QStyleHintReturn | returnData
| ) |  |  |

QRect subControlRect | ( | self, |
|  | QStyle::ComplexControl | control,
|  | QStyleOptionComplex | opt,
|  | QStyle::SubControl | subControl,
|  | QWidget | w
| ) |  |  |

QRect subElementRect | ( | self, |
|  | QStyle::SubElement | subRect,
|  | QStyleOption | opt,
|  | QWidget | w
| ) |  |  |

unpolish | ( | self, |
|  | QWidget | a0
| ) |  |  |

unpolish | ( | self, |
|  | QApplication | a0
| ) |  |  |

int widgetLayoutProp | ( | self, |
|  | KStyle.WidgetType | widgetType,
|  | int | metric,
|  | QStyleOption | opt=0,
|  | QWidget | w=0
| ) |  |  |

Used to obtain information about KStyle layout properties and metrics.

The default implementation returns values which are set using setWidgetLayoutProp(), so normally it's not necessary to implement it yourself.

Note:
  This method is not meant to be accessible from outside KStyle.

Parameters:

  | widgetType | the widget type context where the metric property belongs to
  | metric | the value of this property is requested
  | opt | Qt option parameters
  | w | the actual widget this call is related to

## Static Method Documentation

QStyle::ControlElement customControlElement | ( | QString | element,
|  | QWidget | widget
| ) |  |  |

QStyle::StyleHint customStyleHint | ( | QString | element,
|  | QWidget | widget
| ) |  |  |

Runtime element extension This is just convenience and does /not/ require the using widgets style to inherit KStyle (i.e. calling this while using cleanlooks won't segfault or so but just return 0) Returns a unique id for an element string (e.g. "CE_CapacityBar")

For simplicity, only StyleHints, ControlElements and their SubElements are supported If you don't need extended SubElement functionality, just drop it

Parameters:

  | element | The style element, represented as string. Naming convention: "appname.(2-char-element-type)_element" where the 2-char-element-type is of {SH, CE, SE} (widgets in kdelibs don't have to pass the appname) examples: "CE_CapacityBar", "amarok.CE_Analyzer"
  | widget | Your widget ("this") passing this is mandatory, passing NULL will just return 0

Returns:
  a unique id for the element string or 0, if the element is not supported by the widgets current style

Important notes: 1) If your string lacks the matching "SH_", "CE_" or "SE_" token the element request will be ignored (return is 0) 2) Try to avoid custom elements and use default ones (if possible) to get better style support and keep UI coherency 3) If you cache this value (good idea, this requires a map lookup) don't (!) forget to catch style changes in QWidget.changeEvent()

QStyle::SubElement customSubElement | ( | QString | element,
|  | QWidget | widget
| ) |  |  |

QString defaultStyle | ( |  | ) |

Returns the default widget style.

## Enumeration Documentation

MarginOffsets

These constants describe how to access various fields of a margin property. For example, to set an additional top margin of 2 pixels, use

     setWidgetLayoutProp(WT_SomeWidget, SomeWidget.Margin + Top, 2);

Enumerator:

  MainMargin |
  Top |
  Bot |
  Left |
  Right |
  MarginInc |

WidgetType

This enum is used to represent KStyle's concept of a widget, and to associate drawing requests and metrics with it. The generic value is used for primitives and metrics that are common between many widgets

Enumerator:

  WT_Generic |
  WT_PushButton |
  WT_Splitter |
  WT_CheckBox |
  WT_RadioButton |
  WT_DockWidget |
  WT_ProgressBar |
  WT_MenuBar |
  WT_MenuBarItem |
  WT_Menu |
  WT_MenuItem |
  WT_ScrollBar |
  WT_TabBar |
  WT_TabWidget |
  WT_Slider |
  WT_Tree |
  WT_SpinBox |
  WT_ComboBox |
  WT_Header |
  WT_LineEdit |
  WT_GroupBox |
  WT_StatusBar |
  WT_ToolBar |
  WT_ToolButton |
  WT_ToolBoxTab |
  WT_Window |
  WT_Limit = 0xFFFF |