Qt Jambi Home

com.trolltech.qt.gui
Class QStyle

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QStyle
All Implemented Interfaces:
QtJambiInterface
Direct Known Subclasses:
QCommonStyle

public abstract class QStyle
extends QObject

The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.

Qt contains a set of QStyle subclasses that emulate the styles of the different platforms supported by Qt (QWindowsStyle, QMacStyle, QMotifStyle, etc.). By default, these styles are built into the QtGui library. Styles can also be made available as plugins.

Qt's built-in widgets use QStyle to perform nearly all of their drawing, ensuring that they look exactly like the equivalent native widgets. The diagram below shows a QComboBox in six different styles.

Six combo boxes

Topics:

Setting a Style

The style of the entire application can be set using the QApplication::setStyle() function. It can also be specified by the user of the application, using the -style command-line option:

    ./myapplication -style motif

If no style is specified, Qt will choose the most appropriate style for the user's platform or desktop environment.

A style can also be set on an individual widget using the QWidget::setStyle() function.

Developing Style-Aware Custom Widgets

If you are developing custom widgets and want them to look good on all platforms, you can use QStyle functions to perform parts of the widget drawing, such as drawItemText, drawItemPixmap, drawPrimitive, drawControl, and drawComplexControl.

Most QStyle draw functions take four arguments:

For example, if you want to draw a focus rectangle on your widget, you can write:

    void MyWidget::paintEvent(QPaintEvent * /* event *<!-- noop -->/)
    {
        QPainter painter(this);

        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.backgroundColor = palette().color(QPalette::Background);

        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
    }

QStyle gets all the information it needs to render the graphical element from QStyleOption. The widget is passed as the last argument in case the style needs it to perform special effects (such as animated default buttons on Mac OS X), but it isn't mandatory. In fact, you can use QStyle to draw on any paint device, not just widgets, by setting the QPainter properly.

QStyleOption has various subclasses for the various types of graphical elements that can be drawn. For example, PE_FrameFocusRect expects a QStyleOptionFocusRect argument.

To ensure that drawing operations are as fast as possible, QStyleOption and its subclasses have public data members. See the QStyleOption class documentation for details on how to use it.

For convenience, Qt provides the QStylePainter class, which combines a QStyle, a QPainter, and a QWidget. This makes it possible to write

        QStylePainter painter(this);
        ...
        painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);

instead of

        QPainter painter(this);
        ...
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);

Creating a Custom Style

If you want to design a custom look and feel for your application, the first step is to pick one of the base styles provided with Qt to build your custom style from. The choice will depend on which existing style resembles your style the most.

Depending on which parts of the base style you want to change, you must reimplement the functions that are used to draw those parts of the interface. To illustrate this, we will modify the look of the spin box arrows drawn by QWindowsStyle. The arrows are primitive elements that are drawn by the drawPrimitive function, so we need to reimplement that function. We need the following class declaration:

    class CustomStyle : public QWindowsStyle
    {
        Q_OBJECT

    public:
        CustomStyle()
        ~CustomStyle() {}

        void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                           QPainter *painter, const QWidget *widget) const;
    };

To draw its up and down arrows, QSpinBox uses the PE_IndicatorSpinUp and PE_IndicatorSpinDown primitive elements. Here's how to reimplement the drawPrimitive function to draw them differently:

    void CustomStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                    QPainter *painter, const QWidget *widget) const
    {
        if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) {
            QPolygon points(3);
            int x = option->rect.x();
            int y = option->rect.y();
            int w = option->rect.width() / 2;
            int h = option->rect.height() / 2;
            x += (option->rect.width() - w) / 2;
            y += (option->rect.height() - h) / 2;

            if (element == PE_IndicatorSpinUp) {
                points[0] = QPoint(x, y + h);
                points[1] = QPoint(x + w, y + h);
                points[2] = QPoint(x + w / 2, y);
            } else { // PE_SpinBoxDown
                points[0] = QPoint(x, y);
                points[1] = QPoint(x + w, y);
                points[2] = QPoint(x + w / 2, y + h);
            }

            if (option->state & State_Enabled) {
                painter->setPen(option->palette.mid().color());
                painter->setBrush(option->palette.buttonText());
            } else {
                painter->setPen(option->palette.buttonText().color());
                painter->setBrush(option->palette.mid());
            }
            painter->drawPolygon(points);
        } else {
            QWindowsStyle::drawPrimitive(element, option, painter, widget);
        }
    }

Notice that we don't use the widget argument, except to pass it on to the QWindowStyle::drawPrimitive() function. As mentioned earlier, the information about what is to be drawn and how it should be drawn is specified by a QStyleOption object, so there is no need to ask the widget.

If you need to use the widget argument to obtain additional information, be careful to ensure that it isn't 0 and that it is of the correct type before using it. For example:

        QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget);
        if (spinBox) {
        ...
        }

When implementing a custom style, you cannot assume that the widget is a QSpinBox just because the enum value is called PE_IndicatorSpinUp or PE_IndicatorSpinDown.

The documentation for the Styles example covers this topic in more detail.

Using a Custom Style

There are several ways of using a custom style in a Qt application. The simplest way is call the QApplication::setStyle() static function before creating the QApplication object:

    #include <QtGui>

    #include "customstyle.h"

    int main(int argc, char *argv[])
    {
        QApplication::setStyle(new CustomStyle);
        QApplication app(argc, argv);
        QSpinBox spinBox;
        spinBox.show();
        return app.exec();
    }

You can call QApplication::setStyle() at any time, but by calling it before the constructor, you ensure that the user's preference, set using the -style command-line option, is respected.

You may want to make your style available for use in other applications, some of which may not be yours and are not available for you to recompile. The Qt Plugin system makes it possible to create styles as plugins. Styles created as plugins are loaded as shared objects at runtime by Qt itself. Please refer to the Qt Plugin documentation for more information on how to go about creating a style plugin.

Compile your plugin and put it into Qt's plugins/styles directory. We now have a pluggable style that Qt can load automatically. To use your new style with existing applications, simply start the application with the following argument:

    ./myapplication -style custom

The application will use the look and feel from the custom style you implemented.

Right-to-Left Desktops

Languages written from right to left (such as Arabic and Hebrew) usually also mirror the whole layout of widgets, and require the light to come from the screen's top-right corner instead of top-left.

If you create a custom style, you should take special care when drawing asymmetric elements to make sure that they also look correct in a mirrored layout. An easy way to test your styles is to run applications with the -reverse command-line option or to call QApplication::setLayoutDirection() in your main() function.

Here are some things to keep in mind when making a style work well in a right-to-left environment:

See Also:
QStyleOption, QStylePainter, Example, Implementing Styles and Style Aware Widgets

Nested Class Summary
static class QStyle.ComplexControl
          This enum describes the available complex controls.
static class QStyle.ContentsType
          This enum describes the available contents types.
static class QStyle.ControlElement
          This enum represents a control element.
static class QStyle.PixelMetric
          This enum describes the various available pixel metrics.
static class QStyle.PrimitiveElement
          This enum describes that various primitive elements.
static class QStyle.StandardPixmap
          This enum describes the available standard pixmaps.
static class QStyle.State
          This QFlag class provides flags for the int enum.
static class QStyle.StateFlag
          This enum describes flags that are used when drawing primitive elements.
static class QStyle.StyleHint
          This enum describes the available style hints.
static class QStyle.SubControl
          This enum describes the available sub controls.
static class QStyle.SubElement
          This enum represents a sub-area of a widget.
 
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
QStyle()
          Constructs a style object.
 
Method Summary
static QRect alignedRect(Qt.LayoutDirection direction, Qt.Alignment alignment, QSize size, QRect rectangle)
          Returns a new rectangle of the specified size that is aligned to the given rectangle according to the specified alignment and direction.
 int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation)
          This is an overloaded mthod provided for convenience.
 int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation, QStyleOption option)
          This is an overloaded mthod provided for convenience.
 int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
          Returns the spacing that should be used between controls1 and controls2 in a layout.
 void drawComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPainter p)
          Equivalent to drawComplexControl(cc, opt, p, 0).
abstract  void drawComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPainter p, QWidget widget)
          Draws the given cc using the provided p with the style options specified by opt.
 void drawControl(QStyle.ControlElement element, QStyleOption opt, QPainter p)
          Equivalent to drawControl(element, opt, p, 0).
abstract  void drawControl(QStyle.ControlElement element, QStyleOption opt, QPainter p, QWidget w)
          Draws the given element with the provided p with the style options specified by opt.
 void drawItemPixmap(QPainter painter, QRect rect, int alignment, QPixmap pixmap)
          Draws the given pixmap in the specified rect, according to the specified alignment, using the provided painter.
 void drawItemText(QPainter painter, QRect rect, int flags, QPalette pal, boolean enabled, java.lang.String text)
          Equivalent to drawItemText(painter, rect, flags, pal, enabled, text, QPalette::NoRole).
 void drawItemText(QPainter painter, QRect rect, int flags, QPalette pal, boolean enabled, java.lang.String text, QPalette.ColorRole textRole)
          Draws the given text in the specified rect using the provided painter and pal.
 void drawPrimitive(QStyle.PrimitiveElement pe, QStyleOption opt, QPainter p)
          Equivalent to drawPrimitive(pe, opt, p, 0).
abstract  void drawPrimitive(QStyle.PrimitiveElement pe, QStyleOption opt, QPainter p, QWidget w)
          Draws the given primitive pe with the provided p using the style options specified by opt.
static QStyle fromNativePointer(QNativePointer nativePointer)
          This function returns the QStyle instance pointed to by nativePointer
abstract  QPixmap generatedIconPixmap(QIcon.Mode iconMode, QPixmap pixmap, QStyleOption opt)
          Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into account the palette specified by opt.
 int hitTestComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPoint pt)
          Equivalent to hitTestComplexControl(cc, opt, pt, 0).
abstract  int hitTestComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPoint pt, QWidget widget)
          Returns the sub control at the given pt in the given complex cc (with the style options specified by opt).
 QRect itemPixmapRect(QRect r, int flags, QPixmap pixmap)
          Returns the area within the given r in which to draw the specified pixmap according to the defined flags.
 QRect itemTextRect(QFontMetrics fm, QRect r, int flags, boolean enabled, java.lang.String text)
          Returns the area within the given r in which to draw the provided text according to the specified font fm and flags.
 int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation)
          This is an overloaded mthod provided for convenience.
 int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option)
          This is an overloaded mthod provided for convenience.
 int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
          This is an overloaded mthod provided for convenience.
 int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation)
          This is an overloaded method provided for convenience.
 int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option)
          This is an overloaded method provided for convenience.
 int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
          This slot is called by layoutSpacing() to determine the spacing that should be used between control1 and control2 in a layout.
 int pixelMetric(QStyle.PixelMetric metric)
          Equivalent to pixelMetric(metric, 0, 0).
 int pixelMetric(QStyle.PixelMetric metric, QStyleOption option)
          Equivalent to pixelMetric(metric, option, 0).
abstract  int pixelMetric(QStyle.PixelMetric metric, QStyleOption option, QWidget widget)
          Returns the value of the given pixel metric.
 void polish(QApplication arg__1)
          Late initialization of the given arg__1 object.
 void polish(QPalette arg__1)
          Changes the arg__1 according to style specific requirements for color palettes (if any).
 void polish(QWidget arg__1)
          Initializes the appearance of the given arg__1.
 QSize sizeFromContents(QStyle.ContentsType ct, QStyleOption opt, QSize contentsSize)
          Equivalent to sizeFromContents(ct, opt, contentsSize, 0).
abstract  QSize sizeFromContents(QStyle.ContentsType ct, QStyleOption opt, QSize contentsSize, QWidget w)
          Returns the size of the element described by the specified opt and ct, based on the provided contentsSize.
static int sliderPositionFromValue(int min, int max, int val, int space)
          Equivalent to sliderPositionFromValue(min, max, val, space, false).
static int sliderPositionFromValue(int min, int max, int val, int space, boolean upsideDown)
          Converts the given val to a pixel position.
static int sliderValueFromPosition(int min, int max, int pos, int space)
          Equivalent to sliderValueFromPosition(min, max, pos, space, false).
static int sliderValueFromPosition(int min, int max, int pos, int space, boolean upsideDown)
          Converts the given pixel pos to a logical value.
 QIcon standardIcon(QStyle.StandardPixmap standardIcon)
          Equivalent to standardIcon(standardIcon, 0, 0).
 QIcon standardIcon(QStyle.StandardPixmap standardIcon, QStyleOption option)
          Equivalent to standardIcon(standardIcon, option, 0).
 QIcon standardIcon(QStyle.StandardPixmap standardIcon, QStyleOption option, QWidget widget)
          Returns an icon for the given standardIcon.
protected  QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon)
          Equivalent to standardIconImplementation(standardIcon, 0, 0).
protected  QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon, QStyleOption opt)
          Equivalent to standardIconImplementation(standardIcon, opt, 0).
protected  QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon, QStyleOption opt, QWidget widget)
          Returns an icon for the given standardIcon.
 QPalette standardPalette()
          Returns the style's standard palette.
 int styleHint(QStyle.StyleHint stylehint)
          Equivalent to styleHint(stylehint, 0, 0, 0).
 int styleHint(QStyle.StyleHint stylehint, QStyleOption opt)
          Equivalent to styleHint(stylehint, opt, 0, 0).
 int styleHint(QStyle.StyleHint stylehint, QStyleOption opt, QWidget widget)
          Equivalent to styleHint(stylehint, opt, widget, 0).
abstract  int styleHint(QStyle.StyleHint stylehint, QStyleOption opt, QWidget widget, QStyleHintReturn returnData)
          Returns an integer representing the specified style stylehint for the given widget described by the provided style opt.
 QRect subControlRect(QStyle.ComplexControl cc, QStyleOptionComplex opt, int sc)
          Equivalent to subControlRect(cc, opt, sc, 0).
abstract  QRect subControlRect(QStyle.ComplexControl cc, QStyleOptionComplex opt, int sc, QWidget widget)
          Returns the rectangle containing the specified sc of the given complex cc (with the style specified by opt).
 QRect subElementRect(QStyle.SubElement subElement, QStyleOption option)
          Equivalent to subElementRect(subElement, option, 0).
abstract  QRect subElementRect(QStyle.SubElement subElement, QStyleOption option, QWidget widget)
          Returns the sub-area for the given subElement as described in the provided style option.
 void unpolish(QApplication arg__1)
          Uninitialize the given arg__1.
 void unpolish(QWidget arg__1)
          Uninitialize the given arg__1's appearance.
static Qt.Alignment visualAlignment(Qt.LayoutDirection direction, Qt.Alignment alignment)
          Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLeft or Qt::AlignRight with Qt::AlignAbsolute according to the layout direction.
static Qt.Alignment visualAlignment(Qt.LayoutDirection direction, Qt.AlignmentFlag... alignment)
          Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLeft or Qt::AlignRight with Qt::AlignAbsolute according to the layout direction.
static QPoint visualPos(Qt.LayoutDirection direction, QRect boundingRect, QPoint logicalPos)
          Returns the given logicalPos converted to screen coordinates based on the specified direction.
static QRect visualRect(Qt.LayoutDirection direction, QRect boundingRect, QRect logicalRect)
          Returns the given logicalRect converted to screen coordinates based on the specified direction.
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
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

QStyle

public QStyle()

Constructs a style object.

Method Detail

standardIcon

public final QIcon standardIcon(QStyle.StandardPixmap standardIcon,
                                QStyleOption option)

Equivalent to standardIcon(standardIcon, option, 0).


standardIcon

public final QIcon standardIcon(QStyle.StandardPixmap standardIcon)

Equivalent to standardIcon(standardIcon, 0, 0).


standardIcon

public final QIcon standardIcon(QStyle.StandardPixmap standardIcon,
                                QStyleOption option,
                                QWidget widget)

Returns an icon for the given standardIcon.

The standardIcon is a standard pixmap which can follow some existing GUI style or guideline. The option argument can be used to pass extra information required when defining the appropriate icon. The widget argument is optional and can also be used to aid the determination of the icon.

Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide your own icons in a QStyle subclass, reimplement the standardIconImplementation slot in your subclass instead. The standardIcon function will dynamically detect the slot and call it.

See Also:
standardIconImplementation, standardPixmap

standardIconImplementation

protected final QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon,
                                                 QStyleOption opt)

Equivalent to standardIconImplementation(standardIcon, opt, 0).


standardIconImplementation

protected final QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon)

Equivalent to standardIconImplementation(standardIcon, 0, 0).


standardIconImplementation

protected QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon,
                                           QStyleOption opt,
                                           QWidget widget)

Returns an icon for the given standardIcon.

Reimplement this slot to provide your own icons in a QStyle subclass; because of binary compatibility constraints, the standardIcon function (introduced in Qt 4.1) is not virtual. Instead, standardIcon will dynamically detect and call this slot. The default implementation simply calls the standardPixmap() function with the given parameters.

The standardIcon is a standard pixmap which can follow some existing GUI style or guideline. The opt argument can be used to pass extra information required when defining the appropriate icon. The widget argument is optional and can also be used to aid the determination of the icon.

See Also:
standardIcon

drawComplexControl

public final void drawComplexControl(QStyle.ComplexControl cc,
                                     QStyleOptionComplex opt,
                                     QPainter p)

Equivalent to drawComplexControl(cc, opt, p, 0).


drawComplexControl

public abstract void drawComplexControl(QStyle.ComplexControl cc,
                                        QStyleOptionComplex opt,
                                        QPainter p,
                                        QWidget widget)

Draws the given cc using the provided p with the style options specified by opt.

The widget argument is optional and can be used as aid in drawing the control.

The opt parameter is a pointer to a QStyleOptionComplex object that can be cast to the correct subclass using the qstyleoption_cast() function. Note that the rect member of the specified opt must be in logical coordinates. Reimplementations of this function should use visualRect to change the logical coordinates into screen coordinates before calling the drawPrimitive or drawControl function.

The table below is listing the complex control elements and their associated style option subclass. The style options contain all the parameters required to draw the controls, including QStyleOption::state which holds the style flags that are used when drawing. The table also describes which flags that are set when casting the given opt to the appropriate subclass.

Complex ControlQStyleOptionComplex SubclassStyle FlagRemark
CC_SpinBoxQStyleOptionSpinBoxState_EnabledSet if the spin box is enabled.
State_HasFocusSet if the spin box has input focus.
CC_ComboBoxQStyleOptionComboBoxState_EnabledSet if the combobox is enabled.
State_HasFocusSet if the combobox has input focus.
CC_ScrollBarQStyleOptionSliderState_EnabledSet if the scroll bar is enabled.
State_HasFocusSet if the scroll bar has input focus.
CC_SliderQStyleOptionSliderState_EnabledSet if the slider is enabled.
State_HasFocusSet if the slider has input focus.
CC_DialQStyleOptionSliderState_EnabledSet if the dial is enabled.
State_HasFocusSet if the dial has input focus.
CC_ToolButtonQStyleOptionToolButtonState_EnabledSet if the tool button is enabled.
State_HasFocusSet if the tool button has input focus.
State_DownArrowSet if the tool button is down (i.e., a mouse button or the space bar is pressed).
State_OnSet if the tool button is a toggle button and is toggled on.
State_AutoRaiseSet if the tool button has auto-raise enabled.
State_RaisedSet if the button is not down, not on, and doesn't contain the mouse when auto-raise is enabled.
CC_TitleBarQStyleOptionTitleBarState_EnabledSet if the title bar is enabled.
CC_Q3ListViewQStyleOptionQ3ListViewState_EnabledSet if the list view is enabled.

See Also:
drawPrimitive, drawControl

drawControl

public final void drawControl(QStyle.ControlElement element,
                              QStyleOption opt,
                              QPainter p)

Equivalent to drawControl(element, opt, p, 0).


drawControl

public abstract void drawControl(QStyle.ControlElement element,
                                 QStyleOption opt,
                                 QPainter p,
                                 QWidget w)

Draws the given element with the provided p with the style options specified by opt.

The w argument is optional and can be used as aid in drawing the control. The opt parameter is a pointer to a QStyleOption object that can be cast to the correct subclass using the qstyleoption_cast() function.

The table below is listing the control elements and their associated style option subclass. The style options contain all the parameters required to draw the controls, including QStyleOption::state which holds the style flags that are used when drawing. The table also describes which flags that are set when casting the given option to the appropriate subclass.

Note that if a control element is not listed here, it is because it uses a plain QStyleOption object.

Control ElementQStyleOption SubclassStyle FlagRemark
CE_MenuItem, CE_MenuBarItemQStyleOptionMenuItemState_SelectedThe menu item is currently selected item.
State_EnabledThe item is enabled.
State_DownArrowIndicates that a scroll down arrow should be drawn.
State_UpArrowIndicates that a scroll up arrow should be drawn
State_HasFocusSet if the menu bar has input focus.
CE_PushButton, CE_PushButtonBevel, CE_PushButtonLabelQStyleOptionButtonState_EnabledSet if the button is enabled.
State_HasFocusSet if the button has input focus.
State_RaisedSet if the button is not down, not on and not flat.
State_OnSet if the button is a toggle button and is toggled on.
State_SunkenSet if the button is down (i.e., the mouse button or the space bar is pressed on the button).
CE_RadioButton, CE_RadioButtonLabel, CE_CheckBox, CE_CheckBoxLabelQStyleOptionButtonState_EnabledSet if the button is enabled.
State_HasFocusSet if the button has input focus.
State_OnSet if the button is checked.
State_OffSet if the button is not checked.
State_NoChangeSet if the button is in the NoChange state.
State_SunkenSet if the button is down (i.e., the mouse button or the space bar is pressed on the button).
CE_ProgressBarContents, CE_ProgressBarLabel, CE_ProgressBarGrooveQStyleOptionProgressBarState_EnabledSet if the progress bar is enabled.
State_HasFocusSet if the progress bar has input focus.
CE_Header, CE_HeaderSection, CE_HeaderLabelQStyleOptionHeader
CE_TabBarTab, CE_TabBarTabShape, CE_TabBarTabLabelQStyleOptionTabState_EnabledSet if the tab bar is enabled.
State_SelectedThe tab bar is the currently selected tab bar.
State_HasFocusSet if the tab bar tab has input focus.
CE_ToolButtonLabelQStyleOptionToolButtonState_EnabledSet if the tool button is enabled.
State_HasFocusSet if the tool button has input focus.
State_SunkenSet if the tool button is down (i.e., a mouse button or the space bar is pressed).
State_OnSet if the tool button is a toggle button and is toggled on.
State_AutoRaiseSet if the tool button has auto-raise enabled.
State_MouseOverSet if the mouse pointer is over the tool button.
State_RaisedSet if the button is not down and is not on.
CE_ToolBoxTabQStyleOptionToolBoxState_SelectedThe tab is the currently selected tab.
CE_HeaderSectionQStyleOptionHeaderState_SunkenIndicates that the section is pressed.
State_UpArrowIndicates that the sort indicator should be pointing up.
State_DownArrowIndicates that the sort indicator should be pointing down.

See Also:
drawPrimitive, drawComplexControl

drawItemPixmap

public void drawItemPixmap(QPainter painter,
                           QRect rect,
                           int alignment,
                           QPixmap pixmap)

Draws the given pixmap in the specified rect, according to the specified alignment, using the provided painter.

See Also:
drawItemText

drawItemText

public final void drawItemText(QPainter painter,
                               QRect rect,
                               int flags,
                               QPalette pal,
                               boolean enabled,
                               java.lang.String text)

Equivalent to drawItemText(painter, rect, flags, pal, enabled, text, QPalette::NoRole).


drawItemText

public void drawItemText(QPainter painter,
                         QRect rect,
                         int flags,
                         QPalette pal,
                         boolean enabled,
                         java.lang.String text,
                         QPalette.ColorRole textRole)

Draws the given text in the specified rect using the provided painter and pal.

The text is drawn using the painter's pen, and aligned and wrapped according to the specified flags. If an explicit textRole is specified, the text is drawn using the pal's color for the given role. The enabled parameter indicates whether or not the item is enabled; when reimplementing this function, the enabled parameter should influence how the item is drawn.

See Also:
Qt::Alignment, drawItemPixmap

drawPrimitive

public final void drawPrimitive(QStyle.PrimitiveElement pe,
                                QStyleOption opt,
                                QPainter p)

Equivalent to drawPrimitive(pe, opt, p, 0).


drawPrimitive

public abstract void drawPrimitive(QStyle.PrimitiveElement pe,
                                   QStyleOption opt,
                                   QPainter p,
                                   QWidget w)

Draws the given primitive pe with the provided p using the style options specified by opt.

The w argument is optional and may contain a widget that may aid in drawing the primitive element.

The table below is listing the primitive elements and their associated style option subclasses. The style options contain all the parameters required to draw the elements, including QStyleOption::state which holds the style flags that are used when drawing. The table also describes which flags that are set when casting the given option to the appropriate subclass.

Note that if a primitive element is not listed here, it is because it uses a plain QStyleOption object.

Primitive ElementQStyleOption SubclassStyle FlagRemark
PE_FrameFocusRectQStyleOptionFocusRectState_FocusAtBorderWhether the focus is is at the border or inside the widget.
PE_IndicatorCheckBoxQStyleOptionButtonState_NoChangeIndicates a "tri-state" checkbox.
State_OnIndicates the indicator is checked.
PE_IndicatorRadioButtonQStyleOptionButtonState_OnIndicates that a radio button is selected.
PE_Q3CheckListExclusiveIndicator, PE_Q3CheckListIndicatorQStyleOptionQ3ListViewState_OnIndicates whether or not the controller is selected.
State_NoChangeIndicates a "tri-state" controller.
State_EnabledIndicates the controller is enabled.
PE_IndicatorBranchQStyleOptionState_ChildrenIndicates that the control for expanding the tree to show child items, should be drawn.
State_ItemIndicates that a horizontal branch (to show a child item), should be drawn.
State_OpenIndicates that the tree branch is expanded.
State_SiblingIndicates that a vertical line (to show a sibling item), should be drawn.
PE_IndicatorHeaderArrowQStyleOptionHeaderState_UpArrowIndicates that the arrow should be drawn up; otherwise it should be down.
PE_FrameGroupBox, PE_Frame, PE_FrameLineEdit, PE_FrameMenu, PE_FrameDockWidgetQStyleOptionFrameState_SunkenIndicates that the Frame should be sunken.
PE_IndicatorToolBarHandleQStyleOptionState_HorizontalIndicates that the window handle is horizontal instead of vertical.
PE_Q3DockWindowSeparatorQStyleOptionState_HorizontalIndicates that the separator is horizontal instead of vertical.
PE_IndicatorSpinPlus, PE_IndicatorSpinMinus, PE_IndicatorSpinUp, PE_IndicatorSpinDown,QStyleOptionSpinBoxState_SunkenIndicates that the button is pressed.

See Also:
drawComplexControl, drawControl

generatedIconPixmap

public abstract QPixmap generatedIconPixmap(QIcon.Mode iconMode,
                                            QPixmap pixmap,
                                            QStyleOption opt)

Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into account the palette specified by opt.

The opt parameter can pass extra information, but it must contain a palette.

Note that not all pixmaps will conform, in which case the returned pixmap is a plain copy.

See Also:
QIcon

hitTestComplexControl

public final int hitTestComplexControl(QStyle.ComplexControl cc,
                                       QStyleOptionComplex opt,
                                       QPoint pt)

Equivalent to hitTestComplexControl(cc, opt, pt, 0).


hitTestComplexControl

public abstract int hitTestComplexControl(QStyle.ComplexControl cc,
                                          QStyleOptionComplex opt,
                                          QPoint pt,
                                          QWidget widget)

Returns the sub control at the given pt in the given complex cc (with the style options specified by opt).

Note that the pt is expressed in screen coordinates.

The opt argument is a pointer to a QStyleOptionComplex object (or one of its subclasses). The object can be cast to the appropriate type using the qstyleoption_cast() function. See drawComplexControl for details. The widget argument is optional and can contain additional information for the function.

See Also:
drawComplexControl, subControlRect

itemPixmapRect

public QRect itemPixmapRect(QRect r,
                            int flags,
                            QPixmap pixmap)

Returns the area within the given r in which to draw the specified pixmap according to the defined flags.


itemTextRect

public QRect itemTextRect(QFontMetrics fm,
                          QRect r,
                          int flags,
                          boolean enabled,
                          java.lang.String text)

Returns the area within the given r in which to draw the provided text according to the specified font fm and flags. The enabled parameter indicates whether or not the associated item is enabled.

If the given r is larger than the area needed to render the text, the rectangle that is returned will be offset within r according to the specified flags. For example, if flags is Qt::AlignCenter, the returned rectangle will be centered within r. If the given r is smaller than the area needed, the returned rectangle will be the smallest rectangle large enough to render the text.

See Also:
Qt::Alignment

pixelMetric

public final int pixelMetric(QStyle.PixelMetric metric,
                             QStyleOption option)

Equivalent to pixelMetric(metric, option, 0).


pixelMetric

public final int pixelMetric(QStyle.PixelMetric metric)

Equivalent to pixelMetric(metric, 0, 0).


pixelMetric

public abstract int pixelMetric(QStyle.PixelMetric metric,
                                QStyleOption option,
                                QWidget widget)

Returns the value of the given pixel metric.

The specified option and widget can be used for calculating the metric. In general, the widget argument is not used. The option can be cast to the appropriate type using the qstyleoption_cast() function. Note that the option may be zero even for PixelMetrics that can make use of it. See the table below for the appropriate option casts:

Pixel MetricQStyleOption Subclass
PM_SliderControlThicknessQStyleOptionSlider
PM_SliderLengthQStyleOptionSlider
PM_SliderTickmarkOffsetQStyleOptionSlider
PM_SliderSpaceAvailableQStyleOptionSlider
PM_ScrollBarExtentQStyleOptionSlider
PM_TabBarTabOverlapQStyleOptionTab
PM_TabBarTabHSpaceQStyleOptionTab
PM_TabBarTabVSpaceQStyleOptionTab
PM_TabBarBaseHeightQStyleOptionTab
PM_TabBarBaseOverlapQStyleOptionTab

Some pixel metrics are called from widgets and some are only called internally by the style. If the metric is not called by a widget, it is the discretion of the style author to make use of it. For some styles, this may not be appropriate.


polish

public void polish(QPalette arg__1)

Changes the arg__1 according to style specific requirements for color palettes (if any).

See Also:
QPalette, QApplication::setPalette

polish

public void polish(QWidget arg__1)

Initializes the appearance of the given arg__1.

This function is called for every widget at some point after it has been fully created but just before it is shown for the very first time.

Note that the default implementation does nothing. Reasonable actions in this function might be to call the QWidget::setBackgroundMode() function for the widget. Do not use the function to set, for example, the geometry; reimplementing this function do provide a back-door through which the appearance of a widget can be changed, but with Qt 4.0's style engine there is rarely necessary to implement this function; reimplement the drawItemPixmap, drawItemText, drawPrimitive, etc. instead.

The QWidget::inherits() function may provide enough information to allow class-specific customizations. But because new QStyle subclasses are expected to work reasonably with all current and future widgets, limited use of hard-coded customization is recommended.

See Also:
unpolish

polish

public void polish(QApplication arg__1)

Late initialization of the given arg__1 object.


sizeFromContents

public final QSize sizeFromContents(QStyle.ContentsType ct,
                                    QStyleOption opt,
                                    QSize contentsSize)

Equivalent to sizeFromContents(ct, opt, contentsSize, 0).


sizeFromContents

public abstract QSize sizeFromContents(QStyle.ContentsType ct,
                                       QStyleOption opt,
                                       QSize contentsSize,
                                       QWidget w)

Returns the size of the element described by the specified opt and ct, based on the provided contentsSize.

The opt argument is a pointer to a QStyleOption or one of its subclasses. The opt can be cast to the appropriate type using the qstyleoption_cast() function. The w is an optional argument and can contain extra information used for calculating the size.

See the table below for the appropriate opt casts:

Contents TypeQStyleOption Subclass
CT_PushButtonQStyleOptionButton
CT_CheckBoxQStyleOptionButton
CT_RadioButtonQStyleOptionButton
CT_ToolButtonQStyleOptionToolButton
CT_ComboBoxQStyleOptionComboBox
CT_SplitterQStyleOption
CT_Q3DockWindowQStyleOptionQ3DockWindow
CT_ProgressBarQStyleOptionProgressBar
CT_MenuItemQStyleOptionMenuItem

See Also:
ContentsType, QStyleOption

standardPalette

public QPalette standardPalette()

Returns the style's standard palette.

Note that on systems that support system colors, the style's standard palette is not used.


styleHint

public final int styleHint(QStyle.StyleHint stylehint,
                           QStyleOption opt,
                           QWidget widget)

Equivalent to styleHint(stylehint, opt, widget, 0).


styleHint

public final int styleHint(QStyle.StyleHint stylehint,
                           QStyleOption opt)

Equivalent to styleHint(stylehint, opt, 0, 0).


styleHint

public final int styleHint(QStyle.StyleHint stylehint)

Equivalent to styleHint(stylehint, 0, 0, 0).


styleHint

public abstract int styleHint(QStyle.StyleHint stylehint,
                              QStyleOption opt,
                              QWidget widget,
                              QStyleHintReturn returnData)

Returns an integer representing the specified style stylehint for the given widget described by the provided style opt.

Note that currently, the returnData and widget parameters are not used; they are provided for future enhancement. In addition, the opt parameter is used only in case of the SH_ComboBox_Popup, SH_ComboBox_LayoutDirection, and SH_GroupBox_TextLabelColor style hints.


subControlRect

public final QRect subControlRect(QStyle.ComplexControl cc,
                                  QStyleOptionComplex opt,
                                  int sc)

Equivalent to subControlRect(cc, opt, sc, 0).


subControlRect

public abstract QRect subControlRect(QStyle.ComplexControl cc,
                                     QStyleOptionComplex opt,
                                     int sc,
                                     QWidget widget)

Returns the rectangle containing the specified sc of the given complex cc (with the style specified by opt). The rectangle is defined in screen coordinates.

The opt argument is a pointer to QStyleOptionComplex or one of its subclasses, and can be cast to the appropriate type using the qstyleoption_cast() function. See drawComplexControl for details. The widget is optional and can contain additional information for the function.

See Also:
drawComplexControl

subElementRect

public final QRect subElementRect(QStyle.SubElement subElement,
                                  QStyleOption option)

Equivalent to subElementRect(subElement, option, 0).


subElementRect

public abstract QRect subElementRect(QStyle.SubElement subElement,
                                     QStyleOption option,
                                     QWidget widget)

Returns the sub-area for the given subElement as described in the provided style option. The returned rectangle is defined in screen coordinates.

The widget argument is optional and can be used to aid determining the area. The QStyleOption object can be cast to the appropriate type using the qstyleoption_cast() function. See the table below for the appropriate option casts:

Sub ElementQStyleOption Subclass
SE_PushButtonContentsQStyleOptionButton
SE_PushButtonFocusRectQStyleOptionButton
SE_CheckBoxIndicatorQStyleOptionButton
SE_CheckBoxContentsQStyleOptionButton
SE_CheckBoxFocusRectQStyleOptionButton
SE_RadioButtonIndicatorQStyleOptionButton
SE_RadioButtonContentsQStyleOptionButton
SE_RadioButtonFocusRectQStyleOptionButton
SE_ComboBoxFocusRectQStyleOptionComboBox
SE_Q3DockWindowHandleRectQStyleOptionQ3DockWindow
SE_ProgressBarGrooveQStyleOptionProgressBar
SE_ProgressBarContentsQStyleOptionProgressBar
SE_ProgressBarLabelQStyleOptionProgressBar


unpolish

public void unpolish(QApplication arg__1)

Uninitialize the given arg__1.


unpolish

public void unpolish(QWidget arg__1)

Uninitialize the given arg__1's appearance.

This function is the counterpart to polish. It is called for every polished widget whenever the style is dynamically changed; the former style has to unpolish its settings before the new style can polish them again.

Note that unpolish will only be called if the widget is destroyed. This can cause problems in some cases, e.g, if you remove a widget from the UI, cache it, and then reinsert it after the style has changed; some of Qt's classes cache their widgets.

See Also:
polish

alignedRect

public static QRect alignedRect(Qt.LayoutDirection direction,
                                Qt.Alignment alignment,
                                QSize size,
                                QRect rectangle)

Returns a new rectangle of the specified size that is aligned to the given rectangle according to the specified alignment and direction.


sliderPositionFromValue

public static int sliderPositionFromValue(int min,
                                          int max,
                                          int val,
                                          int space)

Equivalent to sliderPositionFromValue(min, max, val, space, false).


sliderPositionFromValue

public static int sliderPositionFromValue(int min,
                                          int max,
                                          int val,
                                          int space,
                                          boolean upsideDown)

Converts the given val to a pixel position. The min parameter maps to 0, max maps to space and other values are distributed evenly in-between.

This function can handle the entire integer range without overflow, providing that space is less than 4096.

By default, this function assumes that the maximum value is on the right for horizontal items and on the bottom for vertical items. Set the upsideDown parameter to true to reverse this behavior.

See Also:
sliderValueFromPosition

sliderValueFromPosition

public static int sliderValueFromPosition(int min,
                                          int max,
                                          int pos,
                                          int space)

Equivalent to sliderValueFromPosition(min, max, pos, space, false).


sliderValueFromPosition

public static int sliderValueFromPosition(int min,
                                          int max,
                                          int pos,
                                          int space,
                                          boolean upsideDown)

Converts the given pixel pos to a logical value. 0 maps to the min parameter, space maps to max and other values are distributed evenly in-between.

This function can handle the entire integer range without overflow.

By default, this function assumes that the maximum value is on the right for horizontal items and on the bottom for vertical items. Set the upsideDown parameter to true to reverse this behavior.

See Also:
sliderPositionFromValue

visualAlignment

public static Qt.Alignment visualAlignment(Qt.LayoutDirection direction,
                                           Qt.AlignmentFlag... alignment)

Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLeft or Qt::AlignRight with Qt::AlignAbsolute according to the layout direction. The other alignment flags are left untouched.

If no horizontal alignment was specified, the function returns the default alignment for the given layout direction.

QWidget::layoutDirection


visualAlignment

public static Qt.Alignment visualAlignment(Qt.LayoutDirection direction,
                                           Qt.Alignment alignment)

Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLeft or Qt::AlignRight with Qt::AlignAbsolute according to the layout direction. The other alignment flags are left untouched.

If no horizontal alignment was specified, the function returns the default alignment for the given layout direction.

QWidget::layoutDirection


visualPos

public static QPoint visualPos(Qt.LayoutDirection direction,
                               QRect boundingRect,
                               QPoint logicalPos)

Returns the given logicalPos converted to screen coordinates based on the specified direction. The boundingRect is used when performing the translation.

See Also:
QWidget::layoutDirection

visualRect

public static QRect visualRect(Qt.LayoutDirection direction,
                               QRect boundingRect,
                               QRect logicalRect)

Returns the given logicalRect converted to screen coordinates based on the specified direction. The boundingRect is used when performing the translation.

This function is provided to support right-to-left desktops, and is typically used in implementations of the subControlRect function.

See Also:
QWidget::layoutDirection

fromNativePointer

public static QStyle fromNativePointer(QNativePointer nativePointer)
This function returns the QStyle instance pointed to by nativePointer

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

combinedLayoutSpacing

public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1,
                                       QSizePolicy.ControlTypes controls2,
                                       Qt.Orientation orientation,
                                       QStyleOption option,
                                       QWidget widget)
Returns the spacing that should be used between controls1 and controls2 in a layout. orientation specifies whether the controls are laid out side by side or stacked vertically. The option parameter can be used to pass extra information about the parent widget. The widget parameter is optional and can also be used if option is 0.

controls1 and controls2 are OR-combination of zero or more \l{QSizePolicy::ControlTypes}{control types}.

This function is called by the layout system. It is used only if PM_LayoutHorizontalSpacing or PM_LayoutVerticalSpacing returns a negative value.


combinedLayoutSpacing

public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1,
                                       QSizePolicy.ControlTypes controls2,
                                       Qt.Orientation orientation,
                                       QStyleOption option)
This is an overloaded mthod provided for convenience.


combinedLayoutSpacing

public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1,
                                       QSizePolicy.ControlTypes controls2,
                                       Qt.Orientation orientation)
This is an overloaded mthod provided for convenience.


layoutSpacing

public final int layoutSpacing(QSizePolicy.ControlType control1,
                               QSizePolicy.ControlType control2,
                               Qt.Orientation orientation,
                               QStyleOption option,
                               QWidget widget)
This is an overloaded mthod provided for convenience.


layoutSpacing

public final int layoutSpacing(QSizePolicy.ControlType control1,
                               QSizePolicy.ControlType control2,
                               Qt.Orientation orientation,
                               QStyleOption option)
This is an overloaded mthod provided for convenience.


layoutSpacing

public final int layoutSpacing(QSizePolicy.ControlType control1,
                               QSizePolicy.ControlType control2,
                               Qt.Orientation orientation)
This is an overloaded mthod provided for convenience.


layoutSpacingImplementation

public final int layoutSpacingImplementation(QSizePolicy.ControlType control1,
                                             QSizePolicy.ControlType control2,
                                             Qt.Orientation orientation,
                                             QStyleOption option,
                                             QWidget widget)
This slot is called by layoutSpacing() to determine the spacing that should be used between control1 and control2 in a layout. orientation specifies whether the controls are laid out side by side or stacked vertically. The option parameter can be used to pass extra information about the parent widget. The widget parameter is optional and can also be used if option is 0.

If you want to provide custom layout spacings in a QStyle subclass, implement a slot called layoutSpacingImplementation() in your subclass. Be aware that this slot will only be called if PM_LayoutHorizontalSpacing or PM_LayoutVerticalSpacing returns a negative value.

The default implementation returns -1.


layoutSpacingImplementation

public final int layoutSpacingImplementation(QSizePolicy.ControlType control1,
                                             QSizePolicy.ControlType control2,
                                             Qt.Orientation orientation,
                                             QStyleOption option)
This is an overloaded method provided for convenience.


layoutSpacingImplementation

public final int layoutSpacingImplementation(QSizePolicy.ControlType control1,
                                             QSizePolicy.ControlType control2,
                                             Qt.Orientation orientation)
This is an overloaded method provided for convenience.


Qt Jambi Home