|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QStyle
public abstract class QStyle
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.
Topics:
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.
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);
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.
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.
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:
Example
,
Implementing Styles and Style Aware WidgetsNested 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 |
---|
public QStyle()
Constructs a style object.
Method Detail |
---|
public final QIcon standardIcon(QStyle.StandardPixmap standardIcon, QStyleOption option)
Equivalent to standardIcon(standardIcon, option, 0).
public final QIcon standardIcon(QStyle.StandardPixmap standardIcon)
Equivalent to standardIcon(standardIcon, 0, 0).
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.
protected final QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon, QStyleOption opt)
Equivalent to standardIconImplementation(standardIcon, opt, 0).
protected final QIcon standardIconImplementation(QStyle.StandardPixmap standardIcon)
Equivalent to standardIconImplementation(standardIcon, 0, 0).
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.
public final void drawComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPainter p)
Equivalent to drawComplexControl(cc, opt, p, 0).
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 Control | QStyleOptionComplex Subclass | Style Flag | Remark |
---|---|---|---|
CC_SpinBox | QStyleOptionSpinBox | State_Enabled | Set if the spin box is enabled. |
State_HasFocus | Set if the spin box has input focus. | ||
CC_ComboBox | QStyleOptionComboBox | State_Enabled | Set if the combobox is enabled. |
State_HasFocus | Set if the combobox has input focus. | ||
CC_ScrollBar | QStyleOptionSlider | State_Enabled | Set if the scroll bar is enabled. |
State_HasFocus | Set if the scroll bar has input focus. | ||
CC_Slider | QStyleOptionSlider | State_Enabled | Set if the slider is enabled. |
State_HasFocus | Set if the slider has input focus. | ||
CC_Dial | QStyleOptionSlider | State_Enabled | Set if the dial is enabled. |
State_HasFocus | Set if the dial has input focus. | ||
CC_ToolButton | QStyleOptionToolButton | State_Enabled | Set if the tool button is enabled. |
State_HasFocus | Set if the tool button has input focus. | ||
State_DownArrow | Set if the tool button is down (i.e., a mouse button or the space bar is pressed). | ||
State_On | Set if the tool button is a toggle button and is toggled on. | ||
State_AutoRaise | Set if the tool button has auto-raise enabled. | ||
State_Raised | Set if the button is not down, not on, and doesn't contain the mouse when auto-raise is enabled. | ||
CC_TitleBar | QStyleOptionTitleBar | State_Enabled | Set if the title bar is enabled. |
CC_Q3ListView | QStyleOptionQ3ListView | State_Enabled | Set if the list view is enabled. |
public final void drawControl(QStyle.ControlElement element, QStyleOption opt, QPainter p)
Equivalent to drawControl(element, opt, p, 0).
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 Element | QStyleOption Subclass | Style Flag | Remark |
---|---|---|---|
CE_MenuItem, CE_MenuBarItem | QStyleOptionMenuItem | State_Selected | The menu item is currently selected item. |
State_Enabled | The item is enabled. | ||
State_DownArrow | Indicates that a scroll down arrow should be drawn. | ||
State_UpArrow | Indicates that a scroll up arrow should be drawn | ||
State_HasFocus | Set if the menu bar has input focus. | ||
CE_PushButton, CE_PushButtonBevel, CE_PushButtonLabel | QStyleOptionButton | State_Enabled | Set if the button is enabled. |
State_HasFocus | Set if the button has input focus. | ||
State_Raised | Set if the button is not down, not on and not flat. | ||
State_On | Set if the button is a toggle button and is toggled on. | ||
State_Sunken | Set 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_CheckBoxLabel | QStyleOptionButton | State_Enabled | Set if the button is enabled. |
State_HasFocus | Set if the button has input focus. | ||
State_On | Set if the button is checked. | ||
State_Off | Set if the button is not checked. | ||
State_NoChange | Set if the button is in the NoChange state. | ||
State_Sunken | Set if the button is down (i.e., the mouse button or the space bar is pressed on the button). | ||
CE_ProgressBarContents, CE_ProgressBarLabel, CE_ProgressBarGroove | QStyleOptionProgressBar | State_Enabled | Set if the progress bar is enabled. |
State_HasFocus | Set if the progress bar has input focus. | ||
CE_Header, CE_HeaderSection, CE_HeaderLabel | QStyleOptionHeader | ||
CE_TabBarTab, CE_TabBarTabShape, CE_TabBarTabLabel | QStyleOptionTab | State_Enabled | Set if the tab bar is enabled. |
State_Selected | The tab bar is the currently selected tab bar. | ||
State_HasFocus | Set if the tab bar tab has input focus. | ||
CE_ToolButtonLabel | QStyleOptionToolButton | State_Enabled | Set if the tool button is enabled. |
State_HasFocus | Set if the tool button has input focus. | ||
State_Sunken | Set if the tool button is down (i.e., a mouse button or the space bar is pressed). | ||
State_On | Set if the tool button is a toggle button and is toggled on. | ||
State_AutoRaise | Set if the tool button has auto-raise enabled. | ||
State_MouseOver | Set if the mouse pointer is over the tool button. | ||
State_Raised | Set if the button is not down and is not on. | ||
CE_ToolBoxTab | QStyleOptionToolBox | State_Selected | The tab is the currently selected tab. |
CE_HeaderSection | QStyleOptionHeader | State_Sunken | Indicates that the section is pressed. |
State_UpArrow | Indicates that the sort indicator should be pointing up. | ||
State_DownArrow | Indicates that the sort indicator should be pointing down. |
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.
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).
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.
Qt::Alignment
,
drawItemPixmappublic final void drawPrimitive(QStyle.PrimitiveElement pe, QStyleOption opt, QPainter p)
Equivalent to drawPrimitive(pe, opt, p, 0).
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 Element | QStyleOption Subclass | Style Flag | Remark |
---|---|---|---|
PE_FrameFocusRect | QStyleOptionFocusRect | State_FocusAtBorder | Whether the focus is is at the border or inside the widget. |
PE_IndicatorCheckBox | QStyleOptionButton | State_NoChange | Indicates a "tri-state" checkbox. |
State_On | Indicates the indicator is checked. | ||
PE_IndicatorRadioButton | QStyleOptionButton | State_On | Indicates that a radio button is selected. |
PE_Q3CheckListExclusiveIndicator, PE_Q3CheckListIndicator | QStyleOptionQ3ListView | State_On | Indicates whether or not the controller is selected. |
State_NoChange | Indicates a "tri-state" controller. | ||
State_Enabled | Indicates the controller is enabled. | ||
PE_IndicatorBranch | QStyleOption | State_Children | Indicates that the control for expanding the tree to show child items, should be drawn. |
State_Item | Indicates that a horizontal branch (to show a child item), should be drawn. | ||
State_Open | Indicates that the tree branch is expanded. | ||
State_Sibling | Indicates that a vertical line (to show a sibling item), should be drawn. | ||
PE_IndicatorHeaderArrow | QStyleOptionHeader | State_UpArrow | Indicates that the arrow should be drawn up; otherwise it should be down. |
PE_FrameGroupBox, PE_Frame, PE_FrameLineEdit, PE_FrameMenu, PE_FrameDockWidget | QStyleOptionFrame | State_Sunken | Indicates that the Frame should be sunken. |
PE_IndicatorToolBarHandle | QStyleOption | State_Horizontal | Indicates that the window handle is horizontal instead of vertical. |
PE_Q3DockWindowSeparator | QStyleOption | State_Horizontal | Indicates that the separator is horizontal instead of vertical. |
PE_IndicatorSpinPlus, PE_IndicatorSpinMinus, PE_IndicatorSpinUp, PE_IndicatorSpinDown, | QStyleOptionSpinBox | State_Sunken | Indicates that the button is pressed. |
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.
public final int hitTestComplexControl(QStyle.ComplexControl cc, QStyleOptionComplex opt, QPoint pt)
Equivalent to hitTestComplexControl(cc, opt, pt, 0).
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.
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.
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.
Qt::Alignment
public final int pixelMetric(QStyle.PixelMetric metric, QStyleOption option)
Equivalent to pixelMetric(metric, option, 0).
public final int pixelMetric(QStyle.PixelMetric metric)
Equivalent to pixelMetric(metric, 0, 0).
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:
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.
public void polish(QPalette arg__1)
Changes the arg__1 according to style specific requirements for color palettes (if any).
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.
public void polish(QApplication arg__1)
Late initialization of the given arg__1 object.
public final QSize sizeFromContents(QStyle.ContentsType ct, QStyleOption opt, QSize contentsSize)
Equivalent to sizeFromContents(ct, opt, contentsSize, 0).
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:
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.
public final int styleHint(QStyle.StyleHint stylehint, QStyleOption opt, QWidget widget)
Equivalent to styleHint(stylehint, opt, widget, 0).
public final int styleHint(QStyle.StyleHint stylehint, QStyleOption opt)
Equivalent to styleHint(stylehint, opt, 0, 0).
public final int styleHint(QStyle.StyleHint stylehint)
Equivalent to styleHint(stylehint, 0, 0, 0).
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.
public final QRect subControlRect(QStyle.ComplexControl cc, QStyleOptionComplex opt, int sc)
Equivalent to subControlRect(cc, opt, sc, 0).
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.
public final QRect subElementRect(QStyle.SubElement subElement, QStyleOption option)
Equivalent to subElementRect(subElement, option, 0).
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:
public void unpolish(QApplication arg__1)
Uninitialize the given arg__1.
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.
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.
public static int sliderPositionFromValue(int min, int max, int val, int space)
Equivalent to sliderPositionFromValue(min, max, val, space, false).
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.
public static int sliderValueFromPosition(int min, int max, int pos, int space)
Equivalent to sliderValueFromPosition(min, max, pos, space, false).
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.
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
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
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.
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.
public static QStyle fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
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.
public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation, QStyleOption option)
public final int combinedLayoutSpacing(QSizePolicy.ControlTypes controls1, QSizePolicy.ControlTypes controls2, Qt.Orientation orientation)
public final int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
public final int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option)
public final int layoutSpacing(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation)
public final int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option, QWidget widget)
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.
public final int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation, QStyleOption option)
public final int layoutSpacingImplementation(QSizePolicy.ControlType control1, QSizePolicy.ControlType control2, Qt.Orientation orientation)
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |