Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QStyleOption Class Reference

Inheritance diagram for QStyleOption:

QStyleOptionButton QStyleOptionComplex QStyleOptionDockWidget QStyleOptionFocusRect QStyleOptionFrame QStyleOptionGraphicsItem QStyleOptionHeader QStyleOptionMenuItem QStyleOptionProgressBar QStyleOptionQ3DockWindow QStyleOptionQ3ListViewItem QStyleOptionRubberBand QStyleOptionTab QStyleOptionTabBarBase QStyleOptionTabWidgetFrame QStyleOptionToolBar QStyleOptionToolBox QStyleOptionViewItem

List of all members.

Detailed Description

The QStyleOption class stores the parameters used by QStyle functions.

QStyleOption and its subclasses contain all the information that QStyle functions need to draw a graphical element.

For performance reasons, there are few member functions and the access to the member variables is direct (i.e., using the . or -> operator). This low-level feel makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.

The caller of a QStyle function usually creates QStyleOption objects on the stack. This combined with Qt's extensive use of {implicit sharing} for types such as QString, QPalette, and QColor ensures that no memory allocation needlessly takes place.

The following code snippet shows how to use a specific QStyleOption subclass to paint a push button:

snippets/qstyleoption/main.cpp MyPushButton::paintEvent /^/

In our example, the control is a QStyle::CE_PushButton, and according to the QStyle::drawControl() documentation the corresponding class is QStyleOptionButton.

When reimplementing QStyle functions that take a QStyleOption parameter, you often need to cast the QStyleOption to a subclass. For safety, you can use qstyleoption_cast() to ensure that the pointer type is correct. For example:

snippets/qstyleoption/main.cpp MyStyle::drawPrimitive /^/

The qstyleoption_cast() function will return 0 if the object to which option points is not of the correct type.

For an example demonstrating how style options can be used, see the {widgets/styles}{Styles} example.

See also:
QStyle, QStylePainter

Definition at line 63 of file qstyleoption.h.

Public Types

enum  OptionType {
  SO_Default, SO_FocusRect, SO_Button, SO_Tab,
  SO_MenuItem, SO_Frame, SO_ProgressBar, SO_ToolBox,
  SO_Header, SO_Q3DockWindow, SO_DockWidget, SO_Q3ListViewItem,
  SO_ViewItem, SO_TabWidgetFrame, SO_TabBarBase, SO_RubberBand,
  SO_ToolBar, SO_GraphicsItem, SO_Complex = 0xf0000, SO_Slider,
  SO_SpinBox, SO_ToolButton, SO_ComboBox, SO_Q3ListView,
  SO_TitleBar, SO_GroupBox, SO_SizeGrip, SO_CustomBase = 0xf00,
  SO_ComplexCustomBase = 0xf000000
enum  StyleOptionType { Type = SO_Default }
enum  StyleOptionVersion { Version = 1 }

Public Member Functions

void init (const QWidget *w)
void initFrom (const QWidget *w)
QStyleOptionoperator= (const QStyleOption &other)
 QStyleOption (const QStyleOption &other)
 QStyleOption (int version=QStyleOption::Version, int type=SO_Default)
 ~QStyleOption ()

Public Attributes

Qt::LayoutDirection direction
QFontMetrics fontMetrics
QPalette palette
QRect rect
QStyle::State state
int type
int version

Related Functions

(Note that these are not member functions.)

qstyleoption_cast (QStyleOption *option)
qstyleoption_cast (const QStyleOption *option)
 the alignment of the display value for the item

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index