Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QStyleOption

    java.lang.Object
      com.trolltech.qt.internal.QSignalEmitterInternal
          com.trolltech.qt.QSignalEmitter
              com.trolltech.qt.QtJambiObject
                  com.trolltech.qt.gui.QStyleOption

All Implemented Interfaces:
  QtJambiInterface, java.lang.Cloneable

Direct Known Subclasses:
  QStyleOptionButton, QStyleOptionComplex, QStyleOptionDockWidget, QStyleOptionFocusRect, QStyleOptionFrame, QStyleOptionGraphicsItem, QStyleOptionHeader, QStyleOptionMenuItem, QStyleOptionProgressBar, QStyleOptionRubberBand, QStyleOptionTab, QStyleOptionTabBarBase, QStyleOptionTabWidgetFrame, QStyleOptionToolBar, QStyleOptionToolBox, QStyleOptionViewItem

    public class QStyleOption

extends QtJambiObject
implements java.lang.Cloneable

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:

        public void paintEvent(QPaintEvent event)
        {
            QStyleOptionButton optioni = new QStyleOptionButton();
            option.initFrom(this);
            option.state() = isDown() ? QStyle.State.State_Sunken :
                                        QStyle.State.State_Raised;
            if (isDefault())
                option.features().setFlag(QStyleOptionButton.ButtonFeature.DefaultButton);
            option.setText(text());
            option.setIcon(icon());

            QPainter painter = new QPainter(this);
            style().drawControl(QStyle.ControlElement.CE_PushButton, option, painter, this);
        }

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:

        void drawPrimitive(QStyle.PrimitiveElement element,
                           QStyleOption option,
                           QPainter painter,
                           QWidget widget)
        {
            if (element.equals(PrimitiveElement.PE_FrameFocusRect)) {
                QStyleOptionFocusRect focusRectOption =
                        (QStyleOptionFocusRect) option;
                if (focusRectOption != null) {
                    // ...
                }
            }
            // ...
        }

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 Styles example.

See also:
  `QStyle`, and `QStylePainter`.

Nested Class Summary
`static class` | `QStyleOption.OptionType` This enum is used internally by `QStyleOption`, its subclasses, and qstyleoption_cast() to determine the type of style option.
`static class` | `QStyleOption.StyleOptionType` This enum is used to hold information about the type of the style option, and is defined for each `QStyleOption` subclass.
`static class` | `QStyleOption.StyleOptionVersion` This enum is used to hold information about the version of the style option, and is defined for each `QStyleOption` subclass.

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal`

Field Summary

Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`currentSender`

Constructor Summary
`QStyleOption()` Constructs a `QStyleOption` with the specified `version` and `type`.
`QStyleOption(int version)` Constructs a `QStyleOption` with the specified `version` and `type`.
`QStyleOption(int version, int type)` Constructs a `QStyleOption` with the specified `version` and `type`.
`QStyleOption(QStyleOption other)` Constructs a copy of `other`.

Method Summary
`QStyleOption` | `clone()` This method is reimplemented for internal reasons
`Qt.LayoutDirection` | `direction()` This variable holds the text layout direction that should be used when drawing text in the control.
`QFontMetrics` | `fontMetrics()` This variable holds the font metrics that should be used when drawing text in the control.
`void` | `initFrom(QWidget w)` Initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified `widget`.
`QPalette` | `palette()` This variable holds the palette that should be used when painting the control.
`QRect` | `rect()` This variable holds the area that should be used for various calculations and painting.
`void` | `setDirection(Qt.LayoutDirection direction)` This variable holds the text layout direction that should be used when drawing text in the control.
`void` | `setFontMetrics(QFontMetrics fontMetrics)` This variable holds the font metrics that should be used when drawing text in the control.
`void` | `setPalette(QPalette palette)` This variable holds the palette that should be used when painting the control.
`void` | `setRect(QRect rect)` This variable holds the area that should be used for various calculations and painting.
`void` | `setState(QStyle.State state)` This variable holds the style flags that are used when drawing the control.
`void` | `setType(int type)` This variable holds the option type of the style option.
`void` | `setVersion(int version)` This variable holds the version of the style option.
`QStyle.State` | `state()` This variable holds the style flags that are used when drawing the control.
`int` | `type()` This variable holds the option type of the style option.
`int` | `version()` This variable holds the version of the style option.

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`__qt_signalInitialization`

Methods inherited from class java.lang.Object
`getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QStyleOption

    public QStyleOption(QStyleOption other)

  Constructs a copy of `other`.

### QStyleOption

    public QStyleOption(int version)

  Constructs a `QStyleOption` with the specified `version` and `type`.

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

  The state member variable is initialized to `QStyle::State_None` .

See also:
  version, and type.

### QStyleOption

    public QStyleOption()

  Constructs a `QStyleOption` with the specified `version` and `type`.

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

  The state member variable is initialized to `QStyle::State_None` .

See also:
  version, and type.

### QStyleOption

    public QStyleOption(int version,
                        int type)

  Constructs a `QStyleOption` with the specified `version` and `type`.

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

  The state member variable is initialized to `QStyle::State_None` .

See also:
  version, and type.

Method Detail

### initFrom

    public final void initFrom(QWidget w)

  Initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified `widget`.

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

See also:
  `QWidget::layoutDirection()`, `QWidget::rect()`, `QWidget::palette()`, and `QWidget::fontMetrics()`.

### setPalette

    public final void setPalette(QPalette palette)

  This variable holds the palette that should be used when painting the control. By default, the application's default palette is used.

See also:
  `initFrom()`.

### palette

    public final QPalette palette()

  This variable holds the palette that should be used when painting the control. By default, the application's default palette is used.

See also:
  `initFrom()`.

### setVersion

    public final void setVersion(int 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 the qstyleoption_cast() function, you normally don't need to check it.

  The default value is 1.

### version

    public final int 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 the qstyleoption_cast() function, you normally don't need to check it.

  The default value is 1.

### setDirection

    public final void setDirection(Qt.LayoutDirection direction)

  This variable holds the text layout direction that should be used when drawing text in the control. By default, the layout direction is `Qt::LeftToRight` .

See also:
  `initFrom()`.

### direction

    public final Qt.LayoutDirection direction()

  This variable holds the text layout direction that should be used when drawing text in the control. By default, the layout direction is `Qt::LeftToRight` .

See also:
  `initFrom()`.

### setRect

    public final void setRect(QRect 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 a `QStyle::CE_PushButton` element it would be the rectangle for the entire button, while for a `QStyle::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 also:
  `initFrom()`.

### rect

    public final QRect 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 a `QStyle::CE_PushButton` element it would be the rectangle for the entire button, while for a `QStyle::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 also:
  `initFrom()`.

### setType

    public final void setType(int type)

  This variable holds the option type of the style option. The default value is `SO_Default` .

See also:
  `OptionType` .

### type

    public final int type()

  This variable holds the option type of the style option. The default value is `SO_Default` .

See also:
  `OptionType` .

### setState

    public final void setState(QStyle.State state)

  This variable holds the style flags that are used when drawing the control. The default value is `QStyle::State_None` .

See also:
  `initFrom()`, `QStyle::drawPrimitive()`, `QStyle::drawControl()`, `QStyle::drawComplexControl()`, and QStyle::State.

### state

    public final QStyle.State state()

  This variable holds the style flags that are used when drawing the control. The default value is `QStyle::State_None` .

See also:
  `initFrom()`, `QStyle::drawPrimitive()`, `QStyle::drawControl()`, `QStyle::drawComplexControl()`, and QStyle::State.

### setFontMetrics

    public final void setFontMetrics(QFontMetrics 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 also:
  `initFrom()`.

### fontMetrics

    public final QFontMetrics 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 also:
  `initFrom()`.

### clone

    public QStyleOption clone()

  This method is reimplemented for internal reasons

  Overrides:
    `clone` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD