Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QBrush Class Reference

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

#include <qbrush.h>

Public Types

typedef QScopedPointer< QBrushData, QBrushDataPointerDeleterDataPtr
 

Public Functions

const QColorcolor () const
 Returns the brush color. More...
 
DataPtrdata_ptr ()
 
const QGradientgradient () const
 Returns the gradient describing this brush. More...
 
bool isDetached () const
 
bool isOpaque () const
 Returns true if the brush is fully opaque otherwise false. More...
 
const QMatrixmatrix () const
 Returns the current transformation matrix for the brush. More...
 
 operator QVariant () const
 Returns the brush as a QVariant. More...
 
bool operator!= (const QBrush &b) const
 Returns true if the brush is different from the given brush; otherwise returns false. More...
 
QBrushoperator= (const QBrush &brush)
 Assigns the given brush to this brush and returns a reference to this brush. More...
 
bool operator== (const QBrush &b) const
 Returns true if the brush is equal to the given brush; otherwise returns false. More...
 
 QBrush ()
 Constructs a default black brush with the style Qt::NoBrush (i.e. More...
 
 QBrush (Qt::BrushStyle bs)
 Constructs a black brush with the given style. More...
 
 QBrush (const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern)
 Constructs a brush with the given color and style. More...
 
 QBrush (Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern)
 Constructs a brush with the given color and style. More...
 
 QBrush (const QColor &color, const QPixmap &pixmap)
 Constructs a brush with the given color and the custom pattern stored in pixmap. More...
 
 QBrush (Qt::GlobalColor color, const QPixmap &pixmap)
 Constructs a brush with the given color and the custom pattern stored in pixmap. More...
 
 QBrush (const QPixmap &pixmap)
 Constructs a brush with a black color and a texture set to the given pixmap. More...
 
 QBrush (const QImage &image)
 Constructs a brush with a black color and a texture set to the given image. More...
 
 QBrush (const QBrush &brush)
 Constructs a copy of other. More...
 
 QBrush (const QGradient &gradient)
 Constructs a brush based on the given gradient. More...
 
void setColor (const QColor &color)
 Sets the brush color to the given color. More...
 
void setColor (Qt::GlobalColor color)
 Sets the brush color to the given color. More...
 
void setMatrix (const QMatrix &mat)
 Sets matrix as an explicit transformation matrix on the current brush. More...
 
void setStyle (Qt::BrushStyle)
 Sets the brush style to style. More...
 
void setTexture (const QPixmap &pixmap)
 Sets the brush pixmap to pixmap. More...
 
void setTextureImage (const QImage &image)
 Sets the brush image to image. More...
 
void setTransform (const QTransform &)
 Sets matrix as an explicit transformation matrix on the current brush. More...
 
Qt::BrushStyle style () const
 Returns the brush style. More...
 
void swap (QBrush &other)
 Swaps brush other with this brush. More...
 
QPixmap texture () const
 Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set. More...
 
QImage textureImage () const
 Returns the custom brush pattern, or a null image if no custom brush pattern has been set. More...
 
QTransform transform () const
 Returns the current transformation matrix for the brush. More...
 
 ~QBrush ()
 Destroys the brush. More...
 

Private Functions

void cleanUp (QBrushData *x)
 
void detach (Qt::BrushStyle newStyle)
 
void init (const QColor &color, Qt::BrushStyle bs)
 Initializes the brush. More...
 

Properties

QScopedPointer< QBrushData, QBrushDataPointerDeleterd
 

Friends

bool Q_GUI_EXPORT qHasPixmapTexture (const QBrush &brush)
 
class QPainter
 
class QRasterPaintEngine
 
class QRasterPaintEnginePrivate
 
struct QSpanData
 
class QX11PaintEngine
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QBrush &brush)
 Writes the given brush to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QBrush &brush)
 Reads the given brush from the given stream and returns a reference to the stream. More...
 

Detailed Description

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

QRadialGradient gradient(50, 50, 50, 50, 50);
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:

brush-outline.png
Outlines

To specify the style and color of lines and outlines, use the QPainter's QPen{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 Qt::NoPen{painter.setPen(Qt::NoPen)} to disable this behavior.

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

See also
Qt::BrushStyle, QPainter, QColor

Definition at line 76 of file qbrush.h.

Typedefs

◆ DataPtr

Warning
This function is not part of the public interface.

Definition at line 151 of file qbrush.h.

Constructors and Destructors

◆ QBrush() [1/10]

QBrush::QBrush ( )

Constructs a default black brush with the style Qt::NoBrush (i.e.

this brush will not fill shapes).

Definition at line 426 of file qbrush.cpp.

Referenced by operator>>().

427  : d(nullBrushInstance())
428 {
429  Q_ASSERT(d);
430  d->ref.ref();
431 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAtomicInt ref
Definition: qbrush.h:176

◆ QBrush() [2/10]

QBrush::QBrush ( Qt::BrushStyle  style)

Constructs a black brush with the given style.

See also
setStyle()

Definition at line 466 of file qbrush.cpp.

467 {
468  if (qbrush_check_type(style))
469  init(Qt::black, style);
470  else {
471  d.reset(nullBrushInstance());
472  d->ref.ref();
473  }
474 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QAtomicInt ref
Definition: qbrush.h:176
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [3/10]

QBrush::QBrush ( const QColor color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also
setColor(), setStyle()

Definition at line 482 of file qbrush.cpp.

483 {
484  if (qbrush_check_type(style))
485  init(color, style);
486  else {
487  d.reset(nullBrushInstance());
488  d->ref.ref();
489  }
490 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QAtomicInt ref
Definition: qbrush.h:176
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [4/10]

QBrush::QBrush ( Qt::GlobalColor  color,
Qt::BrushStyle  style = Qt::SolidPattern 
)

Constructs a brush with the given color and style.

See also
setColor(), setStyle()

Definition at line 502 of file qbrush.cpp.

503 {
504  if (qbrush_check_type(style))
505  init(color, style);
506  else {
507  d.reset(nullBrushInstance());
508  d->ref.ref();
509  }
510 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QAtomicInt ref
Definition: qbrush.h:176
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [5/10]

QBrush::QBrush ( const QColor color,
const 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()

Definition at line 522 of file qbrush.cpp.

523 {
524  init(color, Qt::TexturePattern);
525  setTexture(pixmap);
526 }
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
Definition: qbrush.cpp:802
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [6/10]

QBrush::QBrush ( Qt::GlobalColor  color,
const 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()

Definition at line 538 of file qbrush.cpp.

539 {
541  setTexture(pixmap);
542 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
Definition: qbrush.cpp:802
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [7/10]

QBrush::QBrush ( const 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()

Definition at line 440 of file qbrush.cpp.

441 {
443  setTexture(pixmap);
444 }
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
Definition: qbrush.cpp:802
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [8/10]

QBrush::QBrush ( const 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()

Definition at line 454 of file qbrush.cpp.

455 {
457  setTextureImage(image);
458 }
void setTextureImage(const QImage &image)
Sets the brush image to image.
Definition: qbrush.cpp:856
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ QBrush() [9/10]

QBrush::QBrush ( const QBrush brush)

Constructs a copy of other.

Definition at line 548 of file qbrush.cpp.

549  : d(other.d.data())
550 {
551  d->ref.ref();
552 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qbrush.h:176

◆ QBrush() [10/10]

QBrush::QBrush ( const 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).

Definition at line 561 of file qbrush.cpp.

562 {
563  Q_ASSERT_X(gradient.type() != QGradient::NoGradient, "QBrush::QBrush",
564  "QGradient should not be used directly, use the linear, radial\n"
565  "or conical gradients instead");
566 
567  const Qt::BrushStyle enum_table[] = {
571  };
572 
573  init(QColor(), enum_table[gradient.type()]);
574  QGradientBrushData *grad = static_cast<QGradientBrushData *>(d.data());
575  grad->gradient = gradient;
576 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
BrushStyle
Definition: qnamespace.h:1162
QGradient gradient
Definition: qbrush.cpp:233
T * data() const
Returns the value of the pointer referenced by this object.
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
void init(const QColor &color, Qt::BrushStyle bs)
Initializes the brush.
Definition: qbrush.cpp:396

◆ ~QBrush()

QBrush::~QBrush ( )

Destroys the brush.

Definition at line 582 of file qbrush.cpp.

583 {
584 }

Functions

◆ cleanUp()

void QBrush::cleanUp ( QBrushData x)
private

Definition at line 586 of file qbrush.cpp.

587 {
589 }
static void deleteData(QBrushData *d)
Definition: qbrush.cpp:238

◆ color()

const QColor & QBrush::color ( ) const
inline

Returns the brush color.

See also
setColor()

Definition at line 183 of file qbrush.h.

Referenced by QTextEditPrivate::_q_currentCharFormatChanged(), QPdfEnginePrivate::addBrushPattern(), QAccessibleTextWidget::attributes(), QRenderRule::configurePalette(), QCalendarModel::data(), QTextLine::draw(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QCommonStyle::drawControl(), QWindowsVistaStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QStyleHelper::drawDial(), QWindowsCEStyle::drawItemText(), QStyle::drawItemText(), QPainterPrivate::drawOpaqueBackground(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QDirectFBPaintEngine::drawRects(), QWindowsMobileStylePrivate::drawScrollbarGroove(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), QLCDNumberPrivate::drawSegment(), QWindowsMobileStylePrivate::drawTabBarTab(), QWin32PrintEngine::drawTextItem(), QWindowsCEStylePrivate::drawWinCEButton(), QWindowsCEStylePrivate::drawWinCEPanel(), QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitCharFormatStyle(), QTextHtmlExporter::emitFrameStyle(), QVGCompositionHelper::fillBackground(), QX11PaintEnginePrivate::fillPolygon_dev(), QDirectFBPaintEngine::fillRect(), QVGPaintEngine::fillRect(), QPainter::fillRect(), QOpenGLPaintEnginePrivate::flushDrawQueue(), QWindowsMobileStyle::generatedIconPixmap(), getPatternFill(), hash(), QTextControlPrivate::inputMethodEvent(), make_widget_eventUPP(), QWidgetPrivate::mapFromGlobal(), operator<<(), operator>>(), QScreen::paintBackground(), QDecorationWindows::paintButton(), QCommandLinkButton::paintEvent(), QLabel::paintEvent(), QLineEdit::paintEvent(), QWizardHeader::paintEvent(), QColorLuminancePicker::paintEvent(), QmlJSDebugger::ColorPickerTool::pickColor(), QWindowsStyle::polish(), QWindowsXPStyle::polish(), QWindowsVistaStyle::polish(), QWindowsMobileStyle::polish(), QCleanlooksStyle::polish(), QLineControl::processInputMethodEvent(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QSvgPaintEngine::qbrushToSvg(), qDrawEdge(), qDrawPlainRect(), qDrawRoundedCorners(), qDrawShadeLine(), qDrawShadePanel(), qDrawShadeRect(), qDrawWinButton(), qDrawWinPanel(), qt_cleanlooks_draw_mdibutton(), qt_graphicsItem_highlightSelected(), qt_mac_display_change_callbk(), qt_plastique_draw_handle(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), qt_set_windows_color_resources(), QPainter::setBackground(), QVGPaintEnginePrivate::setBrush(), QPainter::setBrush(), QPalette::setColorGroup(), QOpenGLPaintEnginePrivate::setGradientOps(), QPdfBaseEngine::setPen(), QSpanData::setup(), QInputContext::standardFormat(), QCleanlooksStyle::standardPalette(), QGtkStyle::standardPalette(), QWindowsMobileStyle::standardPixmap(), QCleanlooksStyle::styleHint(), QStyleSheetStyle::styleHint(), QPicturePaintEngine::updateBackground(), QX11PaintEngine::updateBrush(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateEmulationSpecifier(), QWin32PrintEngine::updateState(), QTextOdfWriter::writeBlockFormat(), and QTextOdfWriter::writeCharacterFormat().

183 { return d->color; }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
QColor color
Definition: qbrush.h:178

◆ data_ptr()

DataPtr & QBrush::data_ptr ( )
inline
Warning
This function is not part of the public interface.

Definition at line 152 of file qbrush.h.

152 { return d; }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146

◆ detach()

void QBrush::detach ( Qt::BrushStyle  newStyle)
private

Definition at line 592 of file qbrush.cpp.

Referenced by setColor(), setStyle(), setTexture(), setTextureImage(), and setTransform().

593 {
594  if (newStyle == d->style && d->ref == 1)
595  return;
596 
598  switch(newStyle) {
599  case Qt::TexturePattern: {
601  if (d->style == Qt::TexturePattern) {
602  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
603  if (data->m_has_pixmap_texture)
604  tbd->setPixmap(data->pixmap());
605  else
606  tbd->setImage(data->image());
607  }
608  x.reset(tbd);
609  break;
610  }
614  x.reset(new QGradientBrushData);
615  static_cast<QGradientBrushData *>(x.data())->gradient =
616  static_cast<QGradientBrushData *>(d.data())->gradient;
617  break;
618  default:
619  x.reset(new QBrushData);
620  break;
621  }
622  x->ref = 1;
623  x->style = newStyle;
624  x->color = d->color;
625  x->transform = d->transform;
626  d.reset(x.take());
627 }
T * data() const
Returns the value of the pointer referenced by this object.
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
T * take()
Returns the value of the pointer referenced by this object.
QImage & image()
Definition: qbrush.cpp:210
void setPixmap(const QPixmap &pm)
Definition: qbrush.cpp:182
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QTransform transform
Definition: qbrush.h:179
QColor color
Definition: qbrush.h:178
static const char * data(const QByteArray &arr)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
void setImage(const QImage &image)
Definition: qbrush.cpp:196
QAtomicInt ref
Definition: qbrush.h:176
Qt::BrushStyle style
Definition: qbrush.h:177
bool m_has_pixmap_texture
Definition: qbrush.cpp:218
QPixmap & pixmap()
Definition: qbrush.cpp:203

◆ gradient()

const QGradient * QBrush::gradient ( ) const

Returns the gradient describing this brush.

Definition at line 871 of file qbrush.cpp.

Referenced by cgColorForQColor(), QPainterPrivate::checkEmulation(), coordinateMode(), detach(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QEmulationPaintEngine::drawTextItem(), QCoreGraphicsPaintEngine::drawTextItem(), QEmulationPaintEngine::fill(), fillBackground(), QPainter::fillPath(), QPainter::fillRect(), fillRegion(), isOpaque(), needsResolving(), operator<<(), QBrush(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QSvgPaintEngine::qbrushToSvg(), qMapBrushToRect(), qt_isExtendedRadialGradient(), rasterFallbackWarn(), QVGPaintEnginePrivate::setBrush(), QSpanData::setup(), stretchGradientToUserSpace(), QEmulationPaintEngine::stroke(), QPainter::strokePath(), QCoreGraphicsPaintEngine::updateBrush(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QOpenGLPaintEnginePrivate::updateGradient(), and QPdfEnginePrivate::~QPdfEnginePrivate().

872 {
876  return &static_cast<const QGradientBrushData *>(d.data())->gradient;
877  }
878  return 0;
879 }
T * data() const
Returns the value of the pointer referenced by this object.
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
Qt::BrushStyle style
Definition: qbrush.h:177

◆ init()

void QBrush::init ( const QColor color,
Qt::BrushStyle  style 
)
private

Initializes the brush.

Warning
This function is not part of the public interface.

Definition at line 396 of file qbrush.cpp.

Referenced by QBrush().

397 {
398  switch(style) {
399  case Qt::NoBrush:
400  d.reset(nullBrushInstance());
401  d->ref.ref();
402  if (d->color != color) setColor(color);
403  return;
404  case Qt::TexturePattern:
406  break;
411  break;
412  default:
413  d.reset(new QBrushData);
414  break;
415  }
416  d->ref = 1;
417  d->style = style;
418  d->color = color;
419 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
bool ref()
Atomically increments the value of this QAtomicInt.
QColor color
Definition: qbrush.h:178
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition: qbrush.cpp:725
QAtomicInt ref
Definition: qbrush.h:176
Qt::BrushStyle style
Definition: qbrush.h:177

◆ isDetached()

bool QBrush::isDetached ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 186 of file qbrush.h.

186 { return d->ref == 1; }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
QAtomicInt ref
Definition: qbrush.h:176

◆ isOpaque()

bool QBrush::isOpaque ( ) const

Returns true if the brush is fully opaque otherwise false.

A brush is considered opaque if:

  • The alpha component of the color() is 255.
  • Its texture() does not have an alpha channel and is not a QBitmap.
  • The colors in the gradient() all have an alpha component that is 255.
  • It is an extended radial gradient.

Definition at line 910 of file qbrush.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QPaintEngineEx::drawPoints(), QGL2PaintEngineExPrivate::fill(), QVGPaintEngine::fillRect(), QWidgetPrivate::init(), QWidgetPrivate::isBackgroundInherited(), QWidgetPrivate::mapFromGlobal(), QWidgetPrivate::paintBackground(), QGraphicsView::paintEvent(), QMdiArea::setBackground(), QPdfBaseEngine::setPen(), QSpanData::setup(), QGL2PaintEngineExPrivate::stroke(), QX11PaintEngine::updateBrush(), QPainterPrivate::updateEmulationSpecifier(), QDirectFBWindowSurface::updateIsOpaque(), QWidgetPrivate::updateIsOpaque(), QAlphaPaintEngine::updateState(), QPdfBaseEngine::updateState(), and QPdfEnginePrivate::~QPdfEnginePrivate().

911 {
912  bool opaqueColor = d->color.alpha() == 255;
913 
914  // Test awfully simple case first
915  if (d->style == Qt::SolidPattern)
916  return opaqueColor;
917 
918  if (qt_isExtendedRadialGradient(*this))
919  return false;
920 
924  QGradientStops stops = gradient()->stops();
925  for (int i=0; i<stops.size(); ++i)
926  if (stops.at(i).second.alpha() != 255)
927  return false;
928  return true;
929  } else if (d->style == Qt::TexturePattern) {
930  return qHasPixmapTexture(*this)
933  }
934 
935  return false;
936 }
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
T2 second
Definition: qpair.h:66
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush &brush)
Definition: qbrush.cpp:223
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
QColor color
Definition: qbrush.h:178
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition: qpixmap.cpp:599
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Qt::BrushStyle style
Definition: qbrush.h:177
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
Q_GUI_EXPORT bool qt_isExtendedRadialGradient(const QBrush &brush)
Definition: qbrush.cpp:881
bool hasAlphaChannel() const
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false...
Definition: qpixmap.cpp:1965
QImage textureImage() const
Returns the custom brush pattern, or a null image if no custom brush pattern has been set...
Definition: qbrush.cpp:829
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ matrix()

const QMatrix & QBrush::matrix ( ) const
inline

Returns the current transformation matrix for the brush.

Since
4.2
See also
setMatrix()

Definition at line 184 of file qbrush.h.

Referenced by setTransform().

184 { return d->transform.toAffine(); }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
const QMatrix & toAffine() const
Returns the QTransform as an affine matrix.
QTransform transform
Definition: qbrush.h:179

◆ operator QVariant()

QBrush::operator QVariant ( ) const

Returns the brush as a QVariant.

Definition at line 665 of file qbrush.cpp.

666 {
667  return QVariant(QVariant::Brush, this);
668 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QBrush::operator!= ( const QBrush brush) const
inline

Returns true if the brush is different from the given brush; otherwise returns false.

Two brushes are different if they have different styles, colors or transforms or different pixmaps or gradients depending on the style.

See also
operator==()

Definition at line 127 of file qbrush.h.

127 { return !(operator==(b)); }
bool operator==(const QBrush &b) const
Returns true if the brush is equal to the given brush; otherwise returns false.
Definition: qbrush.cpp:1017

◆ operator=()

QBrush & QBrush::operator= ( const QBrush brush)

Assigns the given brush to this brush and returns a reference to this brush.

Definition at line 640 of file qbrush.cpp.

641 {
642  if (d == b.d)
643  return *this;
644 
645  b.d->ref.ref();
646  d.reset(b.d.data());
647  return *this;
648 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.

◆ operator==()

bool QBrush::operator== ( const QBrush brush) const

Returns true if the brush is equal to the given brush; otherwise returns false.

Two brushes are equal if they have equal styles, colors and transforms and equal pixmaps or gradients depending on the style.

See also
operator!=()

Definition at line 1017 of file qbrush.cpp.

1018 {
1019  if (b.d == d)
1020  return true;
1021  if (b.d->style != d->style || b.d->color != d->color || b.d->transform != d->transform)
1022  return false;
1023  switch (d->style) {
1024  case Qt::TexturePattern:
1025  {
1026  const QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap();
1027  const QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap();
1028  return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey());
1029  }
1033  {
1034  const QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data());
1035  const QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data());
1036  return d1->gradient == d2->gradient;
1037  }
1038  default:
1039  return true;
1040  }
1041 }
QGradient gradient
Definition: qbrush.cpp:233
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
QTransform transform
Definition: qbrush.h:179
QColor color
Definition: qbrush.h:178
Qt::BrushStyle style
Definition: qbrush.h:177
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ setColor() [1/2]

void QBrush::setColor ( const 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()

Definition at line 725 of file qbrush.cpp.

Referenced by QSvgAnimateColor::apply(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), qBrushDark(), qBrushLight(), and qBrushSetAlphaF().

726 {
727  detach(d->style);
728  d->color = c;
729 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
QColor color
Definition: qbrush.h:178
Qt::BrushStyle style
Definition: qbrush.h:177

◆ setColor() [2/2]

void QBrush::setColor ( Qt::GlobalColor  color)
inline

Sets the brush color to the given color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 155 of file qbrush.h.

156 { setColor(QColor(acolor)); }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition: qbrush.cpp:725

◆ setMatrix()

void QBrush::setMatrix ( const QMatrix matrix)

Sets matrix as an explicit transformation matrix on the current brush.

Since
4.2

The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See also
matrix()

Definition at line 951 of file qbrush.cpp.

Referenced by QSvgGradientStyle::brush().

952 {
953  setTransform(QTransform(matrix));
954 }
void setTransform(const QTransform &)
Sets matrix as an explicit transformation matrix on the current brush.
Definition: qbrush.cpp:968
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setStyle()

void QBrush::setStyle ( Qt::BrushStyle  style)

Sets the brush style to style.

See also
style()

Definition at line 687 of file qbrush.cpp.

688 {
689  if (d->style == style)
690  return;
691 
692  if (qbrush_check_type(style)) {
693  detach(style);
694  d->style = style;
695  }
696 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
Qt::BrushStyle style
Definition: qbrush.h:177

◆ setTexture()

void QBrush::setTexture ( const 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 (QBitmap{QBitmaps}).

See also
texture()

Definition at line 802 of file qbrush.cpp.

Referenced by QBrush(), qBrushDark(), qBrushLight(), and qBrushSetAlphaF().

803 {
804  if (!pixmap.isNull()) {
806  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
807  data->setPixmap(pixmap);
808  } else {
810  }
811 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
void setPixmap(const QPixmap &pm)
Definition: qbrush.cpp:182
static const char * data(const QByteArray &arr)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ setTextureImage()

void QBrush::setTextureImage ( const QImage image)

Sets the brush image to image.

Since
4.2

The style is set to Qt::TexturePattern.

Note the current brush color will not have any affect on monochrome images, as opposed to calling setTexture() with a QBitmap. If you want to change the color of monochrome image brushes, either convert the image to QBitmap with QBitmap::fromImage() and set the resulting QBitmap as a texture, or change the entries in the color table for the image.

See also
textureImage(), setTexture()

Definition at line 856 of file qbrush.cpp.

Referenced by QWindowsMobileStylePrivate::drawScrollbarGroove(), and QBrush().

857 {
858  if (!image.isNull()) {
860  QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data());
861  data->setImage(image);
862  } else {
864  }
865 }
T * data() const
Returns the value of the pointer referenced by this object.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
static const char * data(const QByteArray &arr)
void setImage(const QImage &image)
Definition: qbrush.cpp:196

◆ setTransform()

void QBrush::setTransform ( const QTransform matrix)

Sets matrix as an explicit transformation matrix on the current brush.

Since
4.3

The brush transformation matrix is merged with QPainter transformation matrix to produce the final result.

See also
transform()

Definition at line 968 of file qbrush.cpp.

Referenced by QOpenGLPaintEnginePrivate::drawImageAsPath(), QEmulationPaintEngine::drawTextItem(), QOpenGLPaintEnginePrivate::drawTiledImageAsPath(), QVGPaintEngine::drawTiledPixmap(), QEmulationPaintEngine::fill(), fillBackground(), operator>>(), setMatrix(), stretchGradientToUserSpace(), QEmulationPaintEngine::stroke(), and QPaintEngineEx::stroke().

969 {
970  detach(d->style);
971  d->transform = matrix;
972 }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void detach(Qt::BrushStyle newStyle)
Definition: qbrush.cpp:592
QTransform transform
Definition: qbrush.h:179
const QMatrix & matrix() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:184
Qt::BrushStyle style
Definition: qbrush.h:177

◆ style()

Qt::BrushStyle QBrush::style ( ) const
inline

Returns the brush style.

See also
setStyle()

Definition at line 182 of file qbrush.h.

Referenced by QPdfEnginePrivate::addBrushPattern(), QTextHtmlParserNode::applyCssDeclarations(), QAccessibleTextWidget::attributes(), QRenderRule::configurePalette(), coordinateMode(), QVGPaintEnginePrivate::draw(), QSvgPolyline::draw(), QTextLayout::draw(), QTextLine::draw(), QRenderRule::drawBackground(), QGL2PaintEngineExPrivate::drawCachedGlyphs(), QOpenGLPaintEnginePrivate::drawItem(), QPainterPrivate::drawOpaqueBackground(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QDirectFBPaintEngine::drawRects(), QPainterPrivate::drawStretchedGradient(), QTextDocumentLayoutPrivate::drawTableCell(), QWin32PrintEngine::drawTextItem(), QWidgetPrivate::drawWidget(), QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitBlockAttributes(), QTextHtmlExporter::emitCharFormatStyle(), QRasterPaintEngine::ensureBrush(), QEmulationPaintEngine::fill(), QOpenGLPaintEngine::fill(), QDirectFBPaintEngine::fill(), QVGPaintEnginePrivate::fill(), QVGCompositionHelper::fillBackground(), fillBackground(), QX11PaintEnginePrivate::fillPolygon_dev(), QBlitterPaintEngine::fillRect(), QDirectFBPaintEngine::fillRect(), QVGPaintEngine::fillRect(), QPainter::fillRect(), fillRegion(), QRenderRule::fixupBorder(), QOpenGLPaintEnginePrivate::flushDrawQueue(), getPatternFill(), hash(), QWidgetPrivate::init(), QTextControlPrivate::inputMethodEvent(), is_brush_transparent(), QWidgetPrivate::isBackgroundInherited(), QWidgetPrivate::mapFromGlobal(), needsResolving(), operator<<(), operator>>(), QScreen::paintBackground(), QPdf::patternForBrush(), QGL2PaintEngineExPrivate::prepareForDraw(), QTextHtmlImporter::processBlockNode(), QLineControl::processInputMethodEvent(), QTextHtmlImporter::processSpecialNodes(), QSvgPaintEngine::qbrushToSvg(), qHasPixmapTexture(), QRenderRule::QRenderRule(), qt_isExtendedRadialGradient(), QTextHtmlImporter::scanTable(), QWorkspace::setBackground(), QPainter::setBackground(), QDirectFBPaintEnginePrivate::setBrush(), QVGPaintEnginePrivate::setBrush(), QPainter::setBrush(), QGL2PaintEngineExPrivate::setBrush(), QOpenGLPaintEnginePrivate::setGradientOps(), QGraphicsOpacityEffect::setOpacityMask(), QDirectFBPaintEnginePrivate::setPen(), QPainter::setPen(), QPdfBaseEngine::setPen(), setPenAndDrawBackground(), setStyle(), stretchGradientToUserSpace(), QSvgNode::strokeWidth(), QStyleSheetStyle::styleHint(), QPicturePaintEngine::updateBackground(), QPicturePaintEngine::updateBrush(), QOpenGLPaintEngine::updateBrush(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateEmulationSpecifier(), QOpenGLPaintEnginePrivate::updateGradient(), QDirectFBWindowSurface::updateIsOpaque(), QWidgetPrivate::updateIsOpaque(), QOpenGLPaintEngine::updatePen(), QAlphaPaintEngine::updateState(), QWin32PrintEngine::updateState(), QOpenGLPaintEngine::updateState(), and QPdfBaseEngine::updateState().

182 { return d->style; }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
Qt::BrushStyle style
Definition: qbrush.h:177

◆ swap()

void QBrush::swap ( QBrush other)
inline

Swaps brush other with this brush.

Since
4.8

This operation is very fast and never fails.

Definition at line 99 of file qbrush.h.

99 { qSwap(d, other.d); }
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ texture()

QPixmap QBrush::texture ( ) const

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

See also
setTexture()

Definition at line 785 of file qbrush.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QPlastiqueStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), QWidgetPrivate::drawWidget(), QTextHtmlExporter::emitBackgroundAttribute(), QX11PaintEnginePrivate::fillPolygon_dev(), QBlitterPaintEngine::fillRect(), QDirectFBPaintEngine::fillRect(), fillRegion(), is_brush_transparent(), isOpaque(), QWidgetPrivate::mapFromGlobal(), operator<<(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qt_mac_display_change_callbk(), qt_mac_fill_background(), QVGPaintEnginePrivate::setBrush(), QGL2PaintEngineExPrivate::setBrush(), QOpenGLPaintEnginePrivate::setGradientOps(), QSpanData::setup(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QPainterPrivate::updateEmulationSpecifier(), and QOpenGLPaintEnginePrivate::updateFragmentProgramData().

786 {
787  return d->style == Qt::TexturePattern
788  ? (static_cast<QTexturedBrushData *>(d.data()))->pixmap()
789  : QPixmap();
790 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
Qt::BrushStyle style
Definition: qbrush.h:177
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ textureImage()

QImage QBrush::textureImage ( ) const

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

Since
4.2

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

See also
setTextureImage()

Definition at line 829 of file qbrush.cpp.

Referenced by QOpenGLPaintEnginePrivate::composite(), QTextHtmlExporter::emitBackgroundAttribute(), is_brush_transparent(), isOpaque(), QSpanData::setup(), and QPainterPrivate::updateEmulationSpecifier().

830 {
831  return d->style == Qt::TexturePattern
832  ? (static_cast<QTexturedBrushData *>(d.data()))->image()
833  : QImage();
834 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
Qt::BrushStyle style
Definition: qbrush.h:177

◆ transform()

QTransform QBrush::transform ( ) const
inline

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QBrush brush 
)
related

Writes the given brush to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1111 of file qbrush.cpp.

1112 {
1113  quint8 style = (quint8) b.style();
1114  bool gradient_style = false;
1115 
1116  if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern
1117  || style == Qt::ConicalGradientPattern)
1118  gradient_style = true;
1119 
1120  if (s.version() < QDataStream::Qt_4_0 && gradient_style)
1121  style = Qt::NoBrush;
1122 
1123  s << style << b.color();
1124  if (b.style() == Qt::TexturePattern) {
1125  s << b.texture();
1126  } else if (s.version() >= QDataStream::Qt_4_0 && gradient_style) {
1127  const QGradient *gradient = b.gradient();
1128  int type_as_int = int(gradient->type());
1129  s << type_as_int;
1130  if (s.version() >= QDataStream::Qt_4_3) {
1131  s << int(gradient->spread());
1132  s << int(gradient->coordinateMode());
1133  }
1134 
1135  if (s.version() >= QDataStream::Qt_4_5)
1136  s << int(gradient->interpolationMode());
1137 
1138  if (sizeof(qreal) == sizeof(double)) {
1139  s << gradient->stops();
1140  } else {
1141  // ensure that we write doubles here instead of streaming the stops
1142  // directly; otherwise, platforms that redefine qreal might generate
1143  // data that cannot be read on other platforms.
1144  QVector<QGradientStop> stops = gradient->stops();
1145  s << quint32(stops.size());
1146  for (int i = 0; i < stops.size(); ++i) {
1147  const QGradientStop &stop = stops.at(i);
1148  s << QPair<double, QColor>(double(stop.first), stop.second);
1149  }
1150  }
1151 
1152  if (gradient->type() == QGradient::LinearGradient) {
1153  s << static_cast<const QLinearGradient *>(gradient)->start();
1154  s << static_cast<const QLinearGradient *>(gradient)->finalStop();
1155  } else if (gradient->type() == QGradient::RadialGradient) {
1156  s << static_cast<const QRadialGradient *>(gradient)->center();
1157  s << static_cast<const QRadialGradient *>(gradient)->focalPoint();
1158  s << (double) static_cast<const QRadialGradient *>(gradient)->radius();
1159  } else { // type == Conical
1160  s << static_cast<const QConicalGradient *>(gradient)->center();
1161  s << (double) static_cast<const QConicalGradient *>(gradient)->angle();
1162  }
1163  }
1164  if (s.version() >= QDataStream::Qt_4_3)
1165  s << b.transform();
1166  return s;
1167 }
double qreal
Definition: qglobal.h:1193
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
unsigned char quint8
Definition: qglobal.h:934
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
Definition: qbrush.cpp:1607
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
qreal angle(const QPointF &p1, const QPointF &p2)
Type type() const
Returns the type of gradient.
Definition: qbrush.h:232
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
unsigned int quint32
Definition: qglobal.h:938
Spread spread() const
Returns the spread method use by this gradient.
Definition: qbrush.h:235
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QBrush brush 
)
related

Reads the given brush from the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1182 of file qbrush.cpp.

1183 {
1184  quint8 style;
1185  QColor color;
1186  s >> style;
1187  s >> color;
1188  if (style == Qt::TexturePattern) {
1189  QPixmap pm;
1190  s >> pm;
1191  b = QBrush(color, pm);
1192  } else if (style == Qt::LinearGradientPattern
1193  || style == Qt::RadialGradientPattern
1194  || style == Qt::ConicalGradientPattern) {
1195 
1196  int type_as_int;
1198  QGradientStops stops;
1202 
1203  s >> type_as_int;
1204  type = QGradient::Type(type_as_int);
1205  if (s.version() >= QDataStream::Qt_4_3) {
1206  s >> type_as_int;
1207  spread = QGradient::Spread(type_as_int);
1208  s >> type_as_int;
1209  cmode = QGradient::CoordinateMode(type_as_int);
1210  }
1211 
1212  if (s.version() >= QDataStream::Qt_4_5) {
1213  s >> type_as_int;
1214  imode = QGradient::InterpolationMode(type_as_int);
1215  }
1216 
1217  if (sizeof(qreal) == sizeof(double)) {
1218  s >> stops;
1219  } else {
1220  quint32 numStops;
1221  double n;
1222  QColor c;
1223 
1224  s >> numStops;
1225  for (quint32 i = 0; i < numStops; ++i) {
1226  s >> n >> c;
1227  stops << QPair<qreal, QColor>(n, c);
1228  }
1229  }
1230 
1231  if (type == QGradient::LinearGradient) {
1232  QPointF p1, p2;
1233  s >> p1;
1234  s >> p2;
1235  QLinearGradient lg(p1, p2);
1236  lg.setStops(stops);
1237  lg.setSpread(spread);
1238  lg.setCoordinateMode(cmode);
1239  lg.setInterpolationMode(imode);
1240  b = QBrush(lg);
1241  } else if (type == QGradient::RadialGradient) {
1242  QPointF center, focal;
1243  double radius;
1244  s >> center;
1245  s >> focal;
1246  s >> radius;
1247  QRadialGradient rg(center, radius, focal);
1248  rg.setStops(stops);
1249  rg.setSpread(spread);
1250  rg.setCoordinateMode(cmode);
1251  rg.setInterpolationMode(imode);
1252  b = QBrush(rg);
1253  } else { // type == QGradient::ConicalGradient
1254  QPointF center;
1255  double angle;
1256  s >> center;
1257  s >> angle;
1258  QConicalGradient cg(center, angle);
1259  cg.setStops(stops);
1260  cg.setSpread(spread);
1261  cg.setCoordinateMode(cmode);
1262  cg.setInterpolationMode(imode);
1263  b = QBrush(cg);
1264  }
1265  } else {
1266  b = QBrush(color, (Qt::BrushStyle)style);
1267  }
1268  if (s.version() >= QDataStream::Qt_4_3) {
1270  s >> transform;
1271  b.setTransform(transform);
1272  }
1273  return s;
1274 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
BrushStyle
Definition: qnamespace.h:1162
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
Definition: qbrush.h:329
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
CoordinateMode
This enum specifies how gradient coordinates map to the paint device on which the gradient is used...
Definition: qbrush.h:219
unsigned char quint8
Definition: qglobal.h:934
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
QTransform transform() const
Returns the current transformation matrix for the brush.
Definition: qbrush.h:185
Type
Specifies the type of gradient.
Definition: qbrush.h:206
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
Spread
Specifies how the area outside the gradient area should be filled.
Definition: qbrush.h:213
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
qreal angle(const QPointF &p1, const QPointF &p2)
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
InterpolationMode
Definition: qbrush.h:225
unsigned int quint32
Definition: qglobal.h:938
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QBrush()
Constructs a default black brush with the style Qt::NoBrush (i.e.
Definition: qbrush.cpp:426
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ qHasPixmapTexture

bool Q_GUI_EXPORT qHasPixmapTexture ( const QBrush brush)
friend

Definition at line 223 of file qbrush.cpp.

Referenced by isOpaque().

224 {
225  if (brush.style() != Qt::TexturePattern)
226  return false;
227  QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data());
228  return tx_data->m_has_pixmap_texture;
229 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QBrushData, QBrushDataPointerDeleter > d
Definition: qbrush.h:146
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
bool m_has_pixmap_texture
Definition: qbrush.cpp:218

◆ QPainter

friend class QPainter
friend

Definition at line 142 of file qbrush.h.

◆ QRasterPaintEngine

friend class QRasterPaintEngine
friend

Definition at line 139 of file qbrush.h.

◆ QRasterPaintEnginePrivate

Definition at line 140 of file qbrush.h.

◆ QSpanData

friend struct QSpanData
friend

Definition at line 141 of file qbrush.h.

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 137 of file qbrush.h.

Properties

◆ d


The documentation for this class was generated from the following files: