• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KStyle Class Reference

#include <kstyle.h>

Inheritance diagram for KStyle:
QCommonStyle

Classes

struct  CheckBox
 
class  ColorMode
 
struct  ColorOption
 
struct  ComboBox
 
struct  DockWidget
 
struct  DoubleButtonOption
 
struct  Generic
 
struct  GroupBox
 
struct  Header
 
struct  IconOption
 
struct  LineEdit
 
struct  Menu
 
struct  MenuBar
 
struct  MenuBarItem
 
struct  MenuItem
 
struct  Option
 
struct  OptionBase
 
struct  ProgressBar
 
struct  PushButton
 
struct  RadioButton
 
struct  ScrollBar
 
struct  Slider
 
struct  SpinBox
 
struct  Splitter
 
struct  StatusBar
 
struct  TabBar
 
struct  TabWidget
 
struct  TextOption
 
struct  TitleButtonOption
 
struct  ToolBar
 
struct  ToolBoxTab
 
struct  ToolButton
 
struct  Tree
 
struct  Window
 

Public Member Functions

 KStyle ()
 
 ~KStyle ()
 

Static Public Member Functions

static ControlElement customControlElement (const QString &element, const QWidget *widget)
 
static StyleHint customStyleHint (const QString &element, const QWidget *widget)
 
static SubElement customSubElement (const QString &element, const QWidget *widget)
 
static QString defaultStyle ()
 

Protected Member Functions

ControlElement newControlElement (const QString &element)
 
StyleHint newStyleHint (const QString &element)
 
SubElement newSubElement (const QString &element)
 

Helper Methods

These are methods helping with QRect handling, for example.

enum  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 = 0xFFFF
}
 
enum  MarginOffsets {
  MainMargin , Top , Bot , Left ,
  Right , MarginInc
}
 
void drawInsideRect (QPainter *p, const QRect &r) const
 
QRect centerRect (const QRect &in, int w, int h) const
 
QRect centerRect (const QRect &in, const QSize &size) const
 
void setWidgetLayoutProp (WidgetType widget, int metric, int value)
 
virtual int widgetLayoutProp (WidgetType widgetType, int metric, const QStyleOption *opt=0, const QWidget *w=0) const
 
virtual void drawKStylePrimitive (WidgetType widgetType, int primitive, const QStyleOption *opt, const QRect &r, const QPalette &pal, State flags, QPainter *p, const QWidget *widget=0, Option *kOpt=0) const
 
template<typename T >
static T extractOption (Option *option)
 

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.

void drawControl (ControlElement elem, const QStyleOption *opt, QPainter *p, const QWidget *w) const
 
void drawPrimitive (PrimitiveElement elem, const QStyleOption *opt, QPainter *p, const QWidget *w) const
 
int pixelMetric (PixelMetric metric, const QStyleOption *opt=0, const QWidget *w=0) const
 
QRect subElementRect (SubElement subRect, const QStyleOption *opt, const QWidget *w) const
 
QSize sizeFromContents (ContentsType type, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const
 
int styleHint (StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const
 
QRect subControlRect (ComplexControl control, const QStyleOptionComplex *opt, SubControl subControl, const QWidget *w) const
 
SubControl hitTestComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w) const
 
void drawComplexControl (ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w) const
 
void polish (QWidget *)
 
void unpolish (QWidget *)
 
void polish (QApplication *)
 
void unpolish (QApplication *)
 
void polish (QPalette &)
 
QRect itemTextRect (const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
 
QRect itemPixmapRect (const QRect &r, int flags, const QPixmap &pixmap) const
 
void drawItemText (QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
 
void drawItemPixmap (QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
 
QPalette standardPalette () const
 
QPixmap standardPixmap (StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
 
QPixmap generatedIconPixmap (QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
 
bool eventFilter (QObject *, QEvent *)
 
int layoutSpacingImplementation (QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget) const
 
QIcon standardIconImplementation (StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
 

Detailed Description

Makes style coding more convenient.

Todo:
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:

  • KStyle option representation
  • KStyle widget representation
Author
Maksim Orlovich (maksim@kde.org)
Sandro Giessl (giessl@kde.org)
See also
KStyleFactory for how to implement the style plugin interface.

Definition at line 85 of file kstyle.h.

Member Enumeration Documentation

◆ MarginOffsets

enum KStyle::MarginOffsets
protected

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);
KStyle::setWidgetLayoutProp
void setWidgetLayoutProp(WidgetType widget, int metric, int value)
Interface for the style to configure various metrics that KStyle has customizable.
Definition: kstyle.cpp:901
Enumerator
MainMargin 

The main margin is applied equally on each side.

In the example above, 'SomeWidget::Margin+MainMargin' is the same as 'SomeWidget::Margin'.

Top 

Apply an additional top margin.

Bot 

Apply an additional bottom margin.

Left 

Apply an additional left margin.

Right 

Apply an additional right margin.

MarginInc 

Used to reserve space in an enum for the Top, Bot, Left, Right margins.

Definition at line 440 of file kstyle.h.

◆ WidgetType

enum KStyle::WidgetType
protected

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 
See also
Generic
WT_PushButton 
See also
PushButton
WT_Splitter 
See also
Splitter
WT_CheckBox 
See also
CheckBox
WT_RadioButton 
See also
RadioButton
WT_DockWidget 
See also
DockWidget
WT_ProgressBar 
See also
ProgressBar
WT_MenuBar 
See also
MenuBar
WT_MenuBarItem 
See also
MenuBarItem
WT_Menu 
See also
Menu
WT_MenuItem 
See also
MenuItem
WT_ScrollBar 
See also
ScrollBar
WT_TabBar 
See also
TabBar
WT_TabWidget 
See also
TabWidget
WT_Slider 
See also
Slider
WT_Tree 
See also
Tree
WT_SpinBox 
See also
SpinBox
WT_ComboBox 
See also
ComboBox
WT_Header 
See also
Header
WT_LineEdit 
See also
LineEdit
WT_GroupBox 
See also
GroupBox
WT_StatusBar 
See also
StatusBar
WT_ToolBar 
See also
ToolBar
WT_ToolButton 
See also
ToolButton
WT_ToolBoxTab 
See also
ToolBoxTab
WT_Window 
See also
Window
WT_Limit 

For enum extensibility.

Definition at line 401 of file kstyle.h.

Constructor & Destructor Documentation

◆ KStyle()

KStyle::KStyle ( )

Definition at line 141 of file kstyle.cpp.

◆ ~KStyle()

KStyle::~KStyle ( )

Definition at line 273 of file kstyle.cpp.

Member Function Documentation

◆ centerRect() [1/2]

QRect KStyle::centerRect ( const QRect &  in,
const QSize &  size 
) const
protected

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

Definition at line 604 of file kstyle.cpp.

◆ centerRect() [2/2]

QRect KStyle::centerRect ( const QRect &  in,
int  w,
int  h 
) const
protected

Returns a w x h QRect center inside the 'in' rectangle.

Definition at line 599 of file kstyle.cpp.

◆ customControlElement()

QStyle::ControlElement KStyle::customControlElement ( const QString &  element,
const QWidget *  widget 
)
static

Definition at line 391 of file kstyle.cpp.

◆ customStyleHint()

QStyle::StyleHint KStyle::customStyleHint ( const QString &  element,
const QWidget *  widget 
)
static

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
elementThe 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"
widgetYour 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()

Definition at line 386 of file kstyle.cpp.

◆ customSubElement()

QStyle::SubElement KStyle::customSubElement ( const QString &  element,
const QWidget *  widget 
)
static

Definition at line 396 of file kstyle.cpp.

◆ defaultStyle()

QString KStyle::defaultStyle ( )
static

Returns the default widget style.

Definition at line 360 of file kstyle.cpp.

◆ drawComplexControl()

void KStyle::drawComplexControl ( ComplexControl  cc,
const QStyleOptionComplex *  opt,
QPainter *  p,
const QWidget *  w 
) const

Definition at line 3155 of file kstyle.cpp.

◆ drawControl()

void KStyle::drawControl ( ControlElement  elem,
const QStyleOption *  opt,
QPainter *  p,
const QWidget *  w 
) const

Definition at line 1327 of file kstyle.cpp.

◆ drawInsideRect()

void KStyle::drawInsideRect ( QPainter *  p,
const QRect &  r 
) const
protected

Draws inside the rectangle using a thinkness 0 pen.

This is what drawRect in Qt3 used to do.

Definition at line 594 of file kstyle.cpp.

◆ drawItemPixmap()

void KStyle::drawItemPixmap ( QPainter *  painter,
const QRect &  rect,
int  alignment,
const QPixmap &  pixmap 
) const

Definition at line 451 of file kstyle.cpp.

◆ drawItemText()

void KStyle::drawItemText ( QPainter *  painter,
const QRect &  rect,
int  flags,
const QPalette &  pal,
bool  enabled,
const QString &  text,
QPalette::ColorRole  textRole = QPalette::NoRole 
) const

Definition at line 444 of file kstyle.cpp.

◆ drawKStylePrimitive()

void KStyle::drawKStylePrimitive ( WidgetType  widgetType,
int  primitive,
const QStyleOption *  opt,
const QRect &  r,
const QPalette &  pal,
State  flags,
QPainter *  p,
const QWidget *  widget = 0,
KStyle::Option *  kOpt = 0 
) const
protectedvirtual

Draws primitives which are used inside KStyle.

KStyle implements various elements of QStyle::ComplexControl and QStyle::ControlElement for convenience. Usually complex drawing is split into smaller pieces, which can be text, icons, or other KStyle primitives. These are painted by this method.

Common Qt option parameters are unpacked for convenience, and information from KStyle are passed as a KStyleOption.

Note
This method is not meant to be accessible from outside KStyle.
You should make sure to use the r parameter for the rectangle, since the QStyleOption is generally unaltered from the original request, even if layout indicates a different painting rectangle.
Parameters
widgetTypethe widget context in which this call is happening in
primitivethe primitive which should be called. Primitives from the Generic struct are not directly coupled to the widgetType , other primitives are usually defined in the struct corresponding to the widget type.
optQt option parameters
rparameter for the rectangle
palthe palette extracted from opt for convenience
flagsstate flags extracted from opt for convenience
pused to draw the primitive
widgetthe widget which is painted on
kOptinformation passed from KStyle

Definition at line 611 of file kstyle.cpp.

◆ drawPrimitive()

void KStyle::drawPrimitive ( PrimitiveElement  elem,
const QStyleOption *  opt,
QPainter *  p,
const QWidget *  w 
) const

Definition at line 979 of file kstyle.cpp.

◆ eventFilter()

bool KStyle::eventFilter ( QObject *  obj,
QEvent *  ev 
)

Definition at line 4374 of file kstyle.cpp.

◆ extractOption()

template<typename T >
T KStyle::extractOption ( Option *  option)
staticprotected

The extractOption method casts the passed in option object, and returns it, if available, or the defaults for the given type.

When implementing drawing of things with associated options, just use this to extract the parameter.

Definition at line 1684 of file kstyle.h.

◆ generatedIconPixmap()

QPixmap KStyle::generatedIconPixmap ( QIcon::Mode  iconMode,
const QPixmap &  pixmap,
const QStyleOption *  opt 
) const

Definition at line 588 of file kstyle.cpp.

◆ hitTestComplexControl()

QStyle::SubControl KStyle::hitTestComplexControl ( ComplexControl  cc,
const QStyleOptionComplex *  opt,
const QPoint &  pt,
const QWidget *  w 
) const

Definition at line 4039 of file kstyle.cpp.

◆ itemPixmapRect()

QRect KStyle::itemPixmapRect ( const QRect &  r,
int  flags,
const QPixmap &  pixmap 
) const

Definition at line 440 of file kstyle.cpp.

◆ itemTextRect()

QRect KStyle::itemTextRect ( const QFontMetrics &  fm,
const QRect &  r,
int  flags,
bool  enabled,
const QString &  text 
) const

Definition at line 434 of file kstyle.cpp.

◆ layoutSpacingImplementation

int KStyle::layoutSpacingImplementation ( QSizePolicy::ControlType  control1,
QSizePolicy::ControlType  control2,
Qt::Orientation  orientation,
const QStyleOption *  option,
const QWidget *  widget 
) const
protectedslot

Definition at line 2833 of file kstyle.cpp.

◆ newControlElement()

QStyle::ControlElement KStyle::newControlElement ( const QString &  element)
protected

Definition at line 349 of file kstyle.cpp.

◆ newStyleHint()

QStyle::StyleHint KStyle::newStyleHint ( const QString &  element)
protected

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
elementThe 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

Definition at line 344 of file kstyle.cpp.

◆ newSubElement()

KStyle::SubElement KStyle::newSubElement ( const QString &  element)
protected

Definition at line 354 of file kstyle.cpp.

◆ pixelMetric()

int KStyle::pixelMetric ( PixelMetric  metric,
const QStyleOption *  opt = 0,
const QWidget *  w = 0 
) const

Definition at line 2589 of file kstyle.cpp.

◆ polish() [1/3]

void KStyle::polish ( QApplication *  a)

Definition at line 422 of file kstyle.cpp.

◆ polish() [2/3]

void KStyle::polish ( QPalette &  pal)

Definition at line 430 of file kstyle.cpp.

◆ polish() [3/3]

void KStyle::polish ( QWidget *  w)

Definition at line 401 of file kstyle.cpp.

◆ setWidgetLayoutProp()

void KStyle::setWidgetLayoutProp ( WidgetType  widget,
int  metric,
int  value 
)
protected

Interface for the style to configure various metrics that KStyle has customizable.

Definition at line 901 of file kstyle.cpp.

◆ sizeFromContents()

QSize KStyle::sizeFromContents ( ContentsType  type,
const QStyleOption *  opt,
const QSize &  contentsSize,
const QWidget *  w 
) const

Definition at line 4092 of file kstyle.cpp.

◆ standardIconImplementation

QIcon KStyle::standardIconImplementation ( StandardPixmap  standardIcon,
const QStyleOption *  option = 0,
const QWidget *  widget = 0 
) const
protectedslot

Definition at line 462 of file kstyle.cpp.

◆ standardPalette()

QPalette KStyle::standardPalette ( ) const

Definition at line 456 of file kstyle.cpp.

◆ standardPixmap()

QPixmap KStyle::standardPixmap ( StandardPixmap  standardPixmap,
const QStyleOption *  opt,
const QWidget *  widget = 0 
) const

Definition at line 583 of file kstyle.cpp.

◆ styleHint()

int KStyle::styleHint ( StyleHint  hint,
const QStyleOption *  opt,
const QWidget *  w,
QStyleHintReturn *  returnData 
) const

Definition at line 2512 of file kstyle.cpp.

◆ subControlRect()

QRect KStyle::subControlRect ( ComplexControl  control,
const QStyleOptionComplex *  opt,
SubControl  subControl,
const QWidget *  w 
) const

Definition at line 3650 of file kstyle.cpp.

◆ subElementRect()

QRect KStyle::subElementRect ( SubElement  subRect,
const QStyleOption *  opt,
const QWidget *  w 
) const

Definition at line 2962 of file kstyle.cpp.

◆ unpolish() [1/2]

void KStyle::unpolish ( QApplication *  a)

Definition at line 426 of file kstyle.cpp.

◆ unpolish() [2/2]

void KStyle::unpolish ( QWidget *  w)

Definition at line 414 of file kstyle.cpp.

◆ widgetLayoutProp()

int KStyle::widgetLayoutProp ( WidgetType  widgetType,
int  metric,
const QStyleOption *  opt = 0,
const QWidget *  w = 0 
) const
protectedvirtual

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
widgetTypethe widget type context where the metric property belongs to
metricthe value of this property is requested
optQt option parameters
wthe actual widget this call is related to

Definition at line 913 of file kstyle.cpp.


The documentation for this class was generated from the following files:
  • kstyle.h
  • kstyle.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal