|
|||||||||
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.gui.QStyleOption
public class QStyleOption
The QStyleOption
class stores the parameters used by QStyle
functions. QStyleOption
and its subclasses contain all the information that QStyle
functions need to draw a graphical element.
For performance reasons, there are few member functions and the access to the member variables is direct (i.e., using the . or -> operator). This low-level feel makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.
The caller of a QStyle
function usually creates QStyleOption
objects on the stack. This combined with Qt's extensive use of implicit sharing for types such as QString, QPalette
, and QColor
ensures that no memory allocation needlessly takes place.
The following code snippet shows how to use a specific QStyleOption
subclass to paint a push button:
public void paintEvent(QPaintEvent event) { QStyleOptionButton optioni = new QStyleOptionButton(); option.initFrom(this); option.state() = isDown() ? QStyle.State.State_Sunken : QStyle.State.State_Raised; if (isDefault()) option.features().setFlag(QStyleOptionButton.ButtonFeature.DefaultButton); option.setText(text()); option.setIcon(icon()); QPainter painter = new QPainter(this); style().drawControl(QStyle.ControlElement.CE_PushButton, option, painter, this); }In our example, the control is a
QStyle::CE_PushButton
, and according to the QStyle::drawControl()
documentation the corresponding class is QStyleOptionButton
. When reimplementing QStyle
functions that take a QStyleOption
parameter, you often need to cast the QStyleOption
to a subclass. For safety, you can use qstyleoption_cast() to ensure that the pointer type is correct. For example:
void drawPrimitive(QStyle.PrimitiveElement element, QStyleOption option, QPainter painter, QWidget widget) { if (element.equals(PrimitiveElement.PE_FrameFocusRect)) { QStyleOptionFocusRect focusRectOption = (QStyleOptionFocusRect) option; if (focusRectOption != null) { // ... } } // ... }The qstyleoption_cast() function will return 0 if the object to which option points is not of the correct type.
For an example demonstrating how style options can be used, see the Styles example.
QStyle
, and QStylePainter
.
Nested Class Summary | |
---|---|
static class |
QStyleOption.OptionType
This enum is used internally by QStyleOption , its subclasses, and qstyleoption_cast() to determine the type of style option. |
static class |
QStyleOption.StyleOptionType
This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass. |
static class |
QStyleOption.StyleOptionVersion
This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QStyleOption()
Constructs a QStyleOption with the specified version and type. |
|
QStyleOption(int version)
Constructs a QStyleOption with the specified version and type. |
|
QStyleOption(int version,
int type)
Constructs a QStyleOption with the specified version and type. |
|
QStyleOption(QStyleOption other)
Constructs a copy of other. |
Method Summary | |
---|---|
QStyleOption |
clone()
This method is reimplemented for internal reasons |
Qt.LayoutDirection |
direction()
This variable holds the text layout direction that should be used when drawing text in the control. |
QFontMetrics |
fontMetrics()
This variable holds the font metrics that should be used when drawing text in the control. |
static QStyleOption |
fromNativePointer(QNativePointer nativePointer)
|
void |
initFrom(QWidget w)
Initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified widget. |
static QNativePointer |
nativePointerArray(QStyleOption[] array)
|
QPalette |
palette()
This variable holds the palette that should be used when painting the control. |
QRect |
rect()
This variable holds the area that should be used for various calculations and painting. |
void |
setDirection(Qt.LayoutDirection direction)
This variable holds the text layout direction that should be used when drawing text in the control. |
void |
setFontMetrics(QFontMetrics fontMetrics)
This variable holds the font metrics that should be used when drawing text in the control. |
void |
setPalette(QPalette palette)
This variable holds the palette that should be used when painting the control. |
void |
setRect(QRect rect)
This variable holds the area that should be used for various calculations and painting. |
void |
setState(QStyle.State state)
This variable holds the style flags that are used when drawing the control. |
void |
setType(int type)
This variable holds the option type of the style option. |
void |
setVersion(int version)
This variable holds the version of the style option. |
QStyle.State |
state()
This variable holds the style flags that are used when drawing the control. |
int |
type()
This variable holds the option type of the style option. |
int |
version()
This variable holds the version of the style option. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QStyleOption(QStyleOption other)
public QStyleOption(int version)
QStyleOption
with the specified version and type. The version has no special meaning for QStyleOption
; it can be used by subclasses to distinguish between different version of the same option type.
The state member variable is initialized to QStyle::State_None
.
public QStyleOption()
QStyleOption
with the specified version and type. The version has no special meaning for QStyleOption
; it can be used by subclasses to distinguish between different version of the same option type.
The state member variable is initialized to QStyle::State_None
.
public QStyleOption(int version, int type)
QStyleOption
with the specified version and type. The version has no special meaning for QStyleOption
; it can be used by subclasses to distinguish between different version of the same option type.
The state member variable is initialized to QStyle::State_None
.
Method Detail |
---|
public final void initFrom(QWidget w)
This is a convenience function; the member variables can also be initialized manually.
QWidget::layoutDirection()
, QWidget::rect()
, QWidget::palette()
, and QWidget::fontMetrics()
.
public final void setPalette(QPalette palette)
initFrom()
.
public final QPalette palette()
initFrom()
.
public final void setVersion(int version)
The default value is 1.
public final int version()
The default value is 1.
public final void setDirection(Qt.LayoutDirection direction)
Qt::LeftToRight
. initFrom()
.
public final Qt.LayoutDirection direction()
Qt::LeftToRight
. initFrom()
.
public final void setRect(QRect rect)
QStyle::CE_PushButton
element it would be the rectangle for the entire button, while for a QStyle::CE_PushButtonLabel
element it would be just the area for the push button label. The default value is a null rectangle, i.e. a rectangle with both the width and the height set to 0.
initFrom()
.
public final QRect rect()
QStyle::CE_PushButton
element it would be the rectangle for the entire button, while for a QStyle::CE_PushButtonLabel
element it would be just the area for the push button label. The default value is a null rectangle, i.e. a rectangle with both the width and the height set to 0.
initFrom()
.
public final void setType(int type)
SO_Default
. OptionType
.
public final int type()
SO_Default
. OptionType
.
public final void setState(QStyle.State state)
QStyle::State_None
. initFrom()
, QStyle::drawPrimitive()
, QStyle::drawControl()
, QStyle::drawComplexControl()
, and QStyle::State.
public final QStyle.State state()
QStyle::State_None
. initFrom()
, QStyle::drawPrimitive()
, QStyle::drawControl()
, QStyle::drawComplexControl()
, and QStyle::State.
public final void setFontMetrics(QFontMetrics fontMetrics)
initFrom()
.
public final QFontMetrics fontMetrics()
initFrom()
.
public static QStyleOption fromNativePointer(QNativePointer nativePointer)
public static QNativePointer nativePointerArray(QStyleOption[] array)
public QStyleOption clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |