Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QStyleOption Class

TheQStyleOption class stores the parameters used byQStyle functions.More...

Public Types

enumOptionType { SO_Button, SO_ComboBox, SO_Complex, SO_Default, ..., SO_Q3ListViewItem }
enumStyleOptionType { Type }
enumStyleOptionVersion { Version }

Public Functions

QStyleOption(int version = QStyleOption::Version, int type = SO_Default)
QStyleOption(const QStyleOption & other)
~QStyleOption()
voidinitFrom(const QWidget * widget)
QStyleOption &operator=(const QStyleOption & other)

Public Variables

Qt::LayoutDirectiondirection
QFontMetricsfontMetrics
QPalettepalette
QRectrect
QStyle::Statestate
inttype
intversion

Related Non-Members

Tqstyleoption_cast(const QStyleOption * option)
Tqstyleoption_cast(QStyleOption * option)

Detailed Description

TheQStyleOption class stores the parameters used byQStyle functions.

QStyleOption and its subclasses contain all the information thatQStyle 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 aQStyle function usually createsQStyleOption objects on the stack. This combined with Qt's extensive use ofimplicit sharing for types such asQString,QPalette, andQColor ensures that no memory allocation needlessly takes place.

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

void MyPushButton::paintEvent(QPaintEvent*){QStyleOptionButton option;    option.initFrom(this);    option.state= isDown()?QStyle::State_Sunken :QStyle::State_Raised;if (isDefault())        option.features|=QStyleOptionButton::DefaultButton;    option.text= text();    option.icon= icon();QPainter painter(this);    style()->drawControl(QStyle::CE_PushButton,&option,&painter,this);}

In our example, the control is aQStyle::CE_PushButton, and according to theQStyle::drawControl() documentation the corresponding class isQStyleOptionButton.

When reimplementingQStyle functions that take aQStyleOption parameter, you often need to cast theQStyleOption to a subclass. For safety, you can useqstyleoption_cast() to ensure that the pointer type is correct. For example:

void MyStyle::drawPrimitive(PrimitiveElement element,constQStyleOption*option,QPainter*painter,constQWidget*widget){if (element== PE_FrameFocusRect) {constQStyleOptionFocusRect*focusRectOption=                qstyleoption_cast<constQStyleOptionFocusRect*>(option);if (focusRectOption) {// ...        }    }// ...}

Theqstyleoption_cast() function will return 0 if the object to whichoption points is not of the correct type.

For an example demonstrating how style options can be used, see theStyles example.

See alsoQStyle andQStylePainter.

Member Type Documentation

enum QStyleOption::OptionType

This enum is used internally byQStyleOption, its subclasses, andqstyleoption_cast() to determine the type of style option. In general you do not need to worry about this unless you want to create your ownQStyleOption subclass and your own styles.

ConstantValueDescription
QStyleOption::SO_Button2QStyleOptionButton
QStyleOption::SO_ComboBox?QStyleOptionComboBox
QStyleOption::SO_Complex0xf0000QStyleOptionComplex
QStyleOption::SO_Default0QStyleOption
QStyleOption::SO_DockWidget10QStyleOptionDockWidget
QStyleOption::SO_FocusRect1QStyleOptionFocusRect
QStyleOption::SO_Frame5QStyleOptionFrameQStyleOptionFrameV2
QStyleOption::SO_GraphicsItem17QStyleOptionGraphicsItem
QStyleOption::SO_GroupBox?QStyleOptionGroupBox
QStyleOption::SO_Header8QStyleOptionHeader
QStyleOption::SO_MenuItem4QStyleOptionMenuItem
QStyleOption::SO_ProgressBar6QStyleOptionProgressBarQStyleOptionProgressBarV2
QStyleOption::SO_RubberBand15QStyleOptionRubberBand
QStyleOption::SO_SizeGrip?QStyleOptionSizeGrip
QStyleOption::SO_Slider?QStyleOptionSlider
QStyleOption::SO_SpinBox?QStyleOptionSpinBox
QStyleOption::SO_Tab3QStyleOptionTab
QStyleOption::SO_TabBarBase14QStyleOptionTabBarBase
QStyleOption::SO_TabWidgetFrame13QStyleOptionTabWidgetFrame
QStyleOption::SO_TitleBar?QStyleOptionTitleBar
QStyleOption::SO_ToolBar16QStyleOptionToolBar
QStyleOption::SO_ToolBox7QStyleOptionToolBox
QStyleOption::SO_ToolButton?QStyleOptionToolButton
QStyleOption::SO_ViewItem12QStyleOptionViewItem (used in Interviews)

The following values are used for custom controls:

ConstantValueDescription
QStyleOption::SO_CustomBase0xf00Reserved for custom QStyleOptions; all custom controls values must be above this value
QStyleOption::SO_ComplexCustomBase0xf000000Reserved for custom QStyleOptions; all custom complex controls values must be above this value

Some style options are defined for variousQt3Support controls:

ConstantValueDescription
QStyleOption::SO_Q3DockWindow9QStyleOptionQ3DockWindow
QStyleOption::SO_Q3ListView?QStyleOptionQ3ListView
QStyleOption::SO_Q3ListViewItem11QStyleOptionQ3ListViewItem

See alsotype.

enum QStyleOption::StyleOptionType

This enum is used to hold information about the type of the style option, and is defined for eachQStyleOption subclass.

ConstantValueDescription
QStyleOption::TypeSO_DefaultThe type of style option provided (SO_Default for this class).

The type is used internally byQStyleOption, its subclasses, andqstyleoption_cast() to determine the type of style option. In general you do not need to worry about this unless you want to create your ownQStyleOption subclass and your own styles.

See alsoStyleOptionVersion.

enum QStyleOption::StyleOptionVersion

This enum is used to hold information about the version of the style option, and is defined for eachQStyleOption subclass.

ConstantValueDescription
QStyleOption::Version11

The version is used byQStyleOption subclasses to implement extensions without breaking compatibility. If you useqstyleoption_cast(), you normally do not need to check it.

See alsoStyleOptionType.

Member Function Documentation

QStyleOption::QStyleOption(int version = QStyleOption::Version,int type = SO_Default)

Constructs aQStyleOption with the specifiedversion andtype.

The version has no special meaning forQStyleOption; it can be used by subclasses to distinguish between different version of the same option type.

Thestate member variable is initialized toQStyle::State_None.

See alsoversion andtype.

QStyleOption::QStyleOption(constQStyleOption & other)

Constructs a copy ofother.

QStyleOption::~QStyleOption()

Destroys this style option object.

void QStyleOption::initFrom(constQWidget * widget)

Initializes thestate,direction,rect,palette, andfontMetrics member variables based on the specifiedwidget.

This is a convenience function; the member variables can also be initialized manually.

This function was introduced in Qt 4.1.

See alsoQWidget::layoutDirection(),QWidget::rect(),QWidget::palette(), andQWidget::fontMetrics().

QStyleOption & QStyleOption::operator=(constQStyleOption & other)

Assignother to thisQStyleOption.

Member Variable Documentation

Qt::LayoutDirection QStyleOption::direction

This variable holds the text layout direction that should be used when drawing text in the control.

By default, the layout direction isQt::LeftToRight.

See alsoinitFrom().

QFontMetrics QStyleOption::fontMetrics

This variable holds the font metrics that should be used when drawing text in the control.

By default, the application's default font is used.

See alsoinitFrom().

QPalette QStyleOption::palette

This variable holds the palette that should be used when painting the control.

By default, the application's default palette is used.

See alsoinitFrom().

QRect QStyleOption::rect

This variable holds the area that should be used for various calculations and painting.

This can have different meanings for different types of elements. For example, for aQStyle::CE_PushButton element it would be the rectangle for the entire button, while for aQStyle::CE_PushButtonLabel element it would be just the area for the push button label.

The default value is a null rectangle, i.e. a rectangle with both the width and the height set to 0.

See alsoinitFrom().

QStyle::State QStyleOption::state

This variable holds the style flags that are used when drawing the control.

The default value isQStyle::State_None.

See alsoinitFrom(),QStyle::drawPrimitive(),QStyle::drawControl(),QStyle::drawComplexControl(), andQStyle::State.

int QStyleOption::type

This variable holds the option type of the style option.

The default value isSO_Default.

See alsoOptionType.

int QStyleOption::version

This variable holds the version of the style option.

This value can be used by subclasses to implement extensions without breaking compatibility. If you use theqstyleoption_cast() function, you normally do not need to check it.

The default value is 1.

Related Non-Members

Tqstyleoption_cast(constQStyleOption * option)

Returns a T or 0 depending on thetype andversion of the givenoption.

Example:

void MyStyle::drawPrimitive(PrimitiveElement element,constQStyleOption*option,QPainter*painter,constQWidget*widget){if (element== PE_FrameFocusRect) {constQStyleOptionFocusRect*focusRectOption=                qstyleoption_cast<constQStyleOptionFocusRect*>(option);if (focusRectOption) {// ...        }    }// ...}

See alsoQStyleOption::type andQStyleOption::version.

Tqstyleoption_cast(QStyleOption * option)

This is an overloaded function.

Returns a T or 0 depending on the type of the givenoption.

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp