com.trolltech.qt.gui
Class QBrush

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QBrush
All Implemented Interfaces:
QtJambiInterface

public class QBrush
extends QtJambiObject

The QBrush class defines the fill pattern of shapes drawn by QPainter.

A brush has a style, a color, a gradient and a texture.

The brush style defines the fill pattern using the Qt::BrushStyle enum. The default brush style is Qt::NoBrush (depending on how you construct a brush). This style tells the painter to not fill shapes. The standard style for filling is Qt::SolidPattern. The style can be set when the brush is created using the appropriate constructor, and in addition the setStyle function provides means for altering the style once the brush is constructed.

Brush Styles

The brush color defines the color of the fill pattern. The color can either be one of Qt's predefined colors, Qt::GlobalColor, or any other custom QColor. The currently set color can be retrieved and altered using the color and setColor functions, respectively.

The gradient defines the gradient fill used when the current style is either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern. Gradient brushes are created by giving a QGradient as a constructor argument when creating the QBrush. Qt provides three different gradients: QLinearGradient, QConicalGradient, and QRadialGradient - all of which inherit QGradient.

        QRadialGradient gradient(50, 50, 50, 50, 50);
        gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1));
        gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));

        QBrush brush(gradient);

The texture defines the pixmap used when the current style is Qt::TexturePattern. You can create a brush with a texture by providing the pixmap when the brush is created or by using setTexture.

Note that applying setTexture makes style == Qt::TexturePattern, regardless of previous style settings. Also, calling setColor will not make a difference if the style is a gradient. The same is the case if the style is Qt::TexturePattern style unless the current texture is a QBitmap.

The isOpaque function returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:

OutlinesTo specify the style and color of lines and outlines, use the QPainter's pen combined with Qt::PenStyle and Qt::GlobalColor:
    QPainter painter(this);

    painter.setBrush(Qt::cyan);
    painter.setPen(Qt::darkCyan);
    painter.drawRect(0, 0, 100,100);

    painter.setBrush(Qt::NoBrush);
    painter.setPen(Qt::darkGreen);
    painter.drawRect(40, 40, 100, 100);

Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use painter.setPen(Qt::NoPen) to disable this behavior.

For more information about painting in general, see The Paint System documentation.

See Also:
Qt::BrushStyle, QPainter, QColor

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
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>
 
Field Summary
static QBrush NoBrush
           
 
Constructor Summary
QBrush()
          Constructs a default black brush with the style Qt.:NoBrush (i.e. this brush will not fill shapes).
QBrush(QBrush brush)
          Constructs a copy of brush.
QBrush(QColor color)
          Equivalent to QBrush(color, Qt::SolidPattern).
QBrush(QColor color, QPixmap pixmap)
          Constructs a brush with the given color and the custom pattern stored in pixmap.
QBrush(QColor color, Qt.BrushStyle bs)
          Constructs a brush with the given color and bs.
QBrush(QGradient gradient)
          Constructs a brush based on the given gradient.
QBrush(QImage image)
          Constructs a brush with a black color and a texture set to the given image.
QBrush(QPixmap pixmap)
          Constructs a brush with a black color and a texture set to the given pixmap.
QBrush(Qt.BrushStyle bs)
          Constructs a black brush with the given bs.
QBrush(Qt.GlobalColor color, QPixmap pixmap)
          Constructs a brush with the given color and the custom pattern stored in pixmap.
 
Method Summary
 QColor color()
          Returns the brush color.
 boolean equals(java.lang.Object other)
          
static QBrush fromNativePointer(QNativePointer nativePointer)
          This function returns the QBrush instance pointed to by nativePointer
 QGradient gradient()
          Returns the gradient describing this brush.
 boolean isOpaque()
          Returns true if the brush is fully opaque otherwise false.
 QMatrix matrix()
          Returns the current transformation matrix for the brush.
static QNativePointer nativePointerArray(QBrush[] array)
          This function returns a QNativePointer that is pointing to the specified QBrush array.
 void readFrom(QDataStream arg__1)
          Reads a QBrush from arg__1.
 void setColor(QColor color)
          Sets the brush color to the given color.
 void setColor(Qt.GlobalColor color)
          Sets the brush color to the given color.
 void setMatrix(QMatrix mat)
          Sets mat as an explicit transformation matrix on the current brush.
 void setStyle(Qt.BrushStyle arg__1)
          Sets the brush style to arg__1.
 void setTexture(QPixmap pixmap)
          Sets the brush pixmap to pixmap.
 void setTextureImage(QImage image)
          Sets the brush image to image.
 void setTransform(QTransform arg__1)
          Sets arg__1 as an explicit transformation matrix on the current brush.
 Qt.BrushStyle style()
          Returns the brush style.
 QPixmap texture()
          Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
 QImage textureImage()
          Returns the custom brush pattern, or a null image if no custom brush pattern has been set.
 QTransform transform()
          Returns the current transformation matrix for the brush.
 void writeTo(QDataStream arg__1)
          Writes thisQBrush to arg__1.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

NoBrush

public static final QBrush NoBrush
Constructor Detail

QBrush

public QBrush(QPixmap pixmap)

Constructs a brush with a black color and a texture set to the given pixmap. The style is set to Qt::TexturePattern.

See Also:
setTexture

QBrush

public QBrush(QColor color)

Equivalent to QBrush(color, Qt::SolidPattern).


QBrush

public QBrush(QColor color,
              Qt.BrushStyle bs)

Constructs a brush with the given color and bs.

See Also:
setColor, setStyle

QBrush

public QBrush(QColor color,
              QPixmap pixmap)

Constructs a brush with the given color and the custom pattern stored in pixmap.

The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.

See Also:
setColor, setPixmap

QBrush

public QBrush()

Constructs a default black brush with the style Qt.:NoBrush (i.e. this brush will not fill shapes).


QBrush

public QBrush(QBrush brush)

Constructs a copy of brush.


QBrush

public QBrush(QGradient gradient)

Constructs a brush based on the given gradient.

The brush style is set to the corresponding gradient style (either Qt::LinearGradientPattern, Qt::RadialGradientPattern or Qt::ConicalGradientPattern).


QBrush

public QBrush(Qt.BrushStyle bs)

Constructs a black brush with the given bs.

See Also:
setStyle

QBrush

public QBrush(Qt.GlobalColor color,
              QPixmap pixmap)

Constructs a brush with the given color and the custom pattern stored in pixmap.

The style is set to Qt::TexturePattern. The color will only have an effect for QBitmaps.

See Also:
setColor, setPixmap

QBrush

public QBrush(QImage image)

Constructs a brush with a black color and a texture set to the given image. The style is set to Qt::TexturePattern.

See Also:
setTextureImage
Method Detail

color

public final QColor color()

Returns the brush color.

See Also:
setColor

gradient

public final QGradient gradient()

Returns the gradient describing this brush.


isOpaque

public final boolean isOpaque()

Returns true if the brush is fully opaque otherwise false. A brush is considered opaque if:


matrix

public final QMatrix matrix()

Returns the current transformation matrix for the brush.

See Also:
setMatrix

writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQBrush to arg__1.


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QBrush from arg__1.


setColor

public final void setColor(Qt.GlobalColor color)

Sets the brush color to the given color.


setColor

public final void setColor(QColor color)

Sets the brush color to the given color.

Note that calling setColor will not make a difference if the style is a gradient. The same is the case if the style is Qt::TexturePattern style unless the current texture is a QBitmap.

See Also:
color

setMatrix

public final void setMatrix(QMatrix mat)

Sets mat as an explicit transformation matrix on the current brush. The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See Also:
matrix

setStyle

public final void setStyle(Qt.BrushStyle arg__1)

Sets the brush style to arg__1.

See Also:
style

setTexture

public final void setTexture(QPixmap pixmap)

Sets the brush pixmap to pixmap. The style is set to Qt::TexturePattern.

The current brush color will only have an effect for monochrome pixmaps, i.e. for QPixmap::depth() == 1 (QBitmaps).

See Also:
texture

setTextureImage

public final void setTextureImage(QImage image)

Sets the brush image to image. The style is set to Qt::TexturePattern.

The current brush color will only have an effect for monochrome images, i.e. for QImage::depth() == 1.

See Also:
textureImage

setTransform

public final void setTransform(QTransform arg__1)

Sets arg__1 as an explicit transformation matrix on the current brush. The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See Also:
transform

style

public final Qt.BrushStyle style()

Returns the brush style.

See Also:
setStyle

texture

public final QPixmap texture()

Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.

See Also:
setTexture

textureImage

public final QImage textureImage()

Returns the custom brush pattern, or a null image if no custom brush pattern has been set.

If the texture was set as a QPixmap it will be converted to a QImage.

See Also:
setTextureImage

transform

public final QTransform transform()

Returns the current transformation matrix for the brush.

See Also:
setTransform

fromNativePointer

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

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

nativePointerArray

public static QNativePointer nativePointerArray(QBrush[] array)
This function returns a QNativePointer that is pointing to the specified QBrush array.

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

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object