Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QGradient Class Reference

Inheritance diagram for QGradient:

QConicalGradient QLinearGradient QRadialGradient

List of all members.


Detailed Description

The QGradient class is used in combination with QBrush to specify gradient fills.

Qt currently supports three types of gradient fills:

Linear gradients interpolate colors between start and end points. Radial gradients interpolate colors between a focal point and end points on a circle surrounding it. Conical gradients interpolate colors around a center point.

A gradient's type can be retrieved using the type() function. Each of the types is represented by a subclass of QGradient:

qgradient-linear.png qgradient-radial.png qgradient-conical.png QLinearGradient QRadialGradient QConicalGradient

The colors in a gradient is defined using stop points of the QGradientStop type, i.e. a position and a color. Use the setColorAt() function to define a single stop point. Alternatively, use the setStops() function to define several stop points in one go. Note that the latter function replaces the current set of stop points.

It is the gradient's complete set of stop points (accessible through the stops() function) that describes how the gradient area should be filled. If no stop points have been specified, a gradient of black at 0 to white at 1 is used.

A diagonal linear gradient from black at (100, 100) to white at (200, 200) could be specified like this:

snippets/brush/brush.cpp LINEAR QLinearGradient Qt::white

A gradient can have an arbitrary number of stop points. The following would create a radial gradient starting with red in the center, blue and then green on the edges:

snippets/brush/brush.cpp RADIAL QRadialGradient Qt::green

It is possible to repeat or reflect the gradient outside its area by specifiying the {QGradient::Spread}{spread method} using the setSpread() function. The default is to pad the outside area with the color at the closest stop point. The currently set {QGradient::Spread}{spread method} can be retrieved using the spread() function. The QGradient::Spread enum defines three different methods:

qradialgradient-pad.png qradialgradient-repeat.png qradialgradient-reflect.png {QGradient::PadSpread}{PadSpread} {QGradient::RepeatSpread}{RepeatSpread} {QGradient::ReflectSpread}{ReflectSpread}

Note that the setSpread() function only has effect for linear and radial gradients. The reason is that the conical gradient is closed by definition, i.e. the conical gradient fills the entire circle from 0 - 360 degrees, while the boundary of a radial or a linear gradient can be specified through its radius or final stop points, respectively.

See also:
{demos/gradients}{The Gradients Demo}, QBrush

Definition at line 186 of file qbrush.h.


Public Types

enum  CoordinateMode { LogicalMode, StretchToDeviceMode, ObjectBoundingMode }
enum  Spread { PadSpread, ReflectSpread, RepeatSpread }
enum  Type { LinearGradient, RadialGradient, ConicalGradient, NoGradient }

Public Member Functions

CoordinateMode coordinateMode () const
bool operator!= (const QGradient &other) const
bool operator== (const QGradient &gradient)
bool operator== (const QGradient &gradient) const
 QGradient ()
void setColorAt (qreal pos, const QColor &color)
void setCoordinateMode (CoordinateMode mode)
void setSpread (Spread spread)
void setStops (const QGradientStops &stops)
Spread spread () const
QGradientStops stops () const
Type type () const

Private Attributes

void * dummy
union {
   struct {
      qreal   angle
      qreal   cx
      qreal   cy
   }   conical
   struct {
      qreal   x1
      qreal   x2
      qreal   y1
      qreal   y2
   }   linear
   struct {
      qreal   cx
      qreal   cy
      qreal   fx
      qreal   fy
      qreal   radius
   }   radial
m_data
Spread m_spread
QGradientStops m_stops
Type m_type

Friends

class QConicalGradient
class QLinearGradient
class QRadialGradient

Related Functions

(Note that these are not member functions.)

 QGradientStop
 QGradientStops

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

Generated by  Doxygen 1.6.0   Back to index