Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
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.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.gui.QStyleOption

All Implemented Interfaces:
  QtJambiInterface

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

    public class QStyleOption

extends QtJambiObject

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:

        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 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 MyStyle::drawPrimitive(PrimitiveElement element,
                                    const QStyleOption *option,
                                    QPainter *painter,
                                    const QWidget *widget)
        {
            if (element == PE_FrameFocusRect) {
                const QStyleOptionFocusRect *focusRectOption =
                        qstyleoption_cast<const QStyleOptionFocusRect *>(option);
                if (focusRectOption) {
                    // ...
                }
            }
            // ...
        }

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`, `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<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>`

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

Method Summary
`Qt.LayoutDirection` | `direction()` Returns the text layout direction that should be used when drawing text in the control.
`QFontMetrics` | `fontMetrics()` Returns the font metrics that should be used when drawing text in the control.
`static QStyleOption` | `fromNativePointer(QNativePointer nativePointer)` This function returns the QStyleOption instance pointed to by nativePointer
`void` | `initFrom(QWidget w)` Initializes the state, direction, rect, palette, and `fontMetrics` member variables based on the specified `w`.
`static QNativePointer` | `nativePointerArray(QStyleOption[] array)` This function returns a QNativePointer that is pointing to the specified QStyleOption array.
`QPalette` | `palette()` Returns the palette that should be used when painting the control.
`QRect` | `rect()` Returns the area that should be used for various calculations and painting.
`void` | `setDirection(Qt.LayoutDirection direction)` Sets the text layout direction that should be used when drawing text in the control to `direction`.
`void` | `setFontMetrics(QFontMetrics fontMetrics)` Sets the font metrics that should be used when drawing text in the control to `fontMetrics`.
`void` | `setPalette(QPalette palette)` Sets the palette that should be used when painting the control to `palette`.
`void` | `setRect(QRect rect)` Sets the area that should be used for various calculations and painting to `rect`.
`void` | `setState(QStyle.State state)` Sets the style flags that are used when drawing the control to `state`.
`void` | `setState(QStyle.StateFlag... state)` Sets the style flags that are used when drawing the control to `state`.
`void` | `setType(int type)` Sets the option type of the style option to `type`.
`void` | `setVersion(int version)` Sets the version of the style option to `version`.
`QStyle.State` | `state()` Returns the style flags that are used when drawing the control.
`int` | `type()` Returns the option type of the style option.
`int` | `version()` Returns the version of the style option.

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

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

Methods inherited from class java.lang.Object
`clone, equals, 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)

  Equivalent to `QStyleOption`(`version`, SO_Default).

### QStyleOption

    public QStyleOption()

  Equivalent to `QStyleOption`(QStyleOption::Version, SO_Default).

### 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, type

Method Detail

### initFrom

    public final void initFrom(QWidget w)

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

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

  See Also:
    `QWidget::layoutDirection`, `QWidget::rect`, `QWidget::palette`, `QWidget::fontMetrics`

### setPalette

    public final void setPalette(QPalette palette)

  Sets the palette that should be used when painting the control to `palette`.

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

  See Also:
    `palette`, `initFrom`

### palette

    public final QPalette palette()

  Returns the palette that should be used when painting the control.

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

  See Also:
    `setPalette`, `initFrom`

### setVersion

    public final void setVersion(int version)

  Sets the version of the style option to `version`.

  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.

  See Also:
    `version`

### version

    public final int version()

  Returns 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.

  See Also:
    `setVersion`

### setDirection

    public final void setDirection(Qt.LayoutDirection direction)

  Sets the text layout direction that should be used when drawing text in the control to `direction`.

  By default, the layout direction is Qt::LeftToRight.

  See Also:
    `direction`, `initFrom`

### direction

    public final Qt.LayoutDirection direction()

  Returns the text layout direction that should be used when drawing text in the control.

  By default, the layout direction is Qt::LeftToRight.

  See Also:
    `setDirection`, `initFrom`

### setRect

    public final void setRect(QRect rect)

  Sets the area that should be used for various calculations and painting to `rect`.

  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:
    `rect`, `initFrom`

### rect

    public final QRect rect()

  Returns 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:
    `setRect`, `initFrom`

### setType

    public final void setType(int type)

  Sets the option type of the style option to `type`.

  The default value is `SO_Default`.

  See Also:
    `type`, `OptionType`

### type

    public final int type()

  Returns the option type of the style option.

  The default value is `SO_Default`.

  See Also:
    `setType`, `OptionType`

### setState

    public final void setState(QStyle.StateFlag... state)

  Sets the style flags that are used when drawing the control to `state`.

  The default value is QStyle::State_None.

  See Also:
    `state`, `initFrom`, `QStyle::drawPrimitive`, `QStyle::drawControl`, `QStyle::drawComplexControl`, `QStyle::State`

### setState

    public final void setState(QStyle.State state)

  Sets the style flags that are used when drawing the control to `state`.

  The default value is QStyle::State_None.

  See Also:
    `state`, `initFrom`, `QStyle::drawPrimitive`, `QStyle::drawControl`, `QStyle::drawComplexControl`, `QStyle::State`

### state

    public final QStyle.State state()

  Returns the style flags that are used when drawing the control.

  The default value is QStyle::State_None.

  See Also:
    `setState`, `initFrom`, `QStyle::drawPrimitive`, `QStyle::drawControl`, `QStyle::drawComplexControl`, `QStyle::State`

### setFontMetrics

    public final void setFontMetrics(QFontMetrics fontMetrics)

  Sets the font metrics that should be used when drawing text in the control to `fontMetrics`.

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

  See Also:
    `fontMetrics`, `initFrom`

### fontMetrics

    public final QFontMetrics fontMetrics()

  Returns the font metrics that should be used when drawing text in the control.

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

  See Also:
    `setFontMetrics`, `initFrom`

### fromNativePointer

    public static QStyleOption fromNativePointer(QNativePointer nativePointer)

  This function returns the QStyleOption instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

### nativePointerArray

    public static QNativePointer nativePointerArray(QStyleOption[] array)

  This function returns a QNativePointer that is pointing to the specified QStyleOption array.

  Parameters:
    `array` - the array that the returned pointer will point to.
  Returns:
    a QNativePointer that is pointing to the specified array.

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