QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Friends | Related Functions | List of all members
QGradient Class Reference

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

#include <qbrush.h>

Inheritance diagram for QGradient:
Inheritance graph
[legend]

Classes

union  QGradientData
 

Public Types

enum  Type { LinearGradient , RadialGradient , ConicalGradient , NoGradient }
 
enum  Spread { PadSpread , ReflectSpread , RepeatSpread }
 
enum  CoordinateMode { LogicalMode , StretchToDeviceMode , ObjectBoundingMode , ObjectMode }
 
enum  InterpolationMode { ColorInterpolation , ComponentInterpolation }
 
enum  Preset {
  WarmFlame = 1 , NightFade = 2 , SpringWarmth = 3 , JuicyPeach = 4 ,
  YoungPassion = 5 , LadyLips = 6 , SunnyMorning = 7 , RainyAshville = 8 ,
  FrozenDreams = 9 , WinterNeva = 10 , DustyGrass = 11 , TemptingAzure = 12 ,
  HeavyRain = 13 , AmyCrisp = 14 , MeanFruit = 15 , DeepBlue = 16 ,
  RipeMalinka = 17 , CloudyKnoxville = 18 , MalibuBeach = 19 , NewLife = 20 ,
  TrueSunset = 21 , MorpheusDen = 22 , RareWind = 23 , NearMoon = 24 ,
  WildApple = 25 , SaintPetersburg = 26 , PlumPlate = 28 , EverlastingSky = 29 ,
  HappyFisher = 30 , Blessing = 31 , SharpeyeEagle = 32 , LadogaBottom = 33 ,
  LemonGate = 34 , ItmeoBranding = 35 , ZeusMiracle = 36 , OldHat = 37 ,
  StarWine = 38 , HappyAcid = 41 , AwesomePine = 42 , NewYork = 43 ,
  ShyRainbow = 44 , MixedHopes = 46 , FlyHigh = 47 , StrongBliss = 48 ,
  FreshMilk = 49 , SnowAgain = 50 , FebruaryInk = 51 , KindSteel = 52 ,
  SoftGrass = 53 , GrownEarly = 54 , SharpBlues = 55 , ShadyWater = 56 ,
  DirtyBeauty = 57 , GreatWhale = 58 , TeenNotebook = 59 , PoliteRumors = 60 ,
  SweetPeriod = 61 , WideMatrix = 62 , SoftCherish = 63 , RedSalvation = 64 ,
  BurningSpring = 65 , NightParty = 66 , SkyGlider = 67 , HeavenPeach = 68 ,
  PurpleDivision = 69 , AquaSplash = 70 , SpikyNaga = 72 , LoveKiss = 73 ,
  CleanMirror = 75 , PremiumDark = 76 , ColdEvening = 77 , CochitiLake = 78 ,
  SummerGames = 79 , PassionateBed = 80 , MountainRock = 81 , DesertHump = 82 ,
  JungleDay = 83 , PhoenixStart = 84 , OctoberSilence = 85 , FarawayRiver = 86 ,
  AlchemistLab = 87 , OverSun = 88 , PremiumWhite = 89 , MarsParty = 90 ,
  EternalConstance = 91 , JapanBlush = 92 , SmilingRain = 93 , CloudyApple = 94 ,
  BigMango = 95 , HealthyWater = 96 , AmourAmour = 97 , RiskyConcrete = 98 ,
  StrongStick = 99 , ViciousStance = 100 , PaloAlto = 101 , HappyMemories = 102 ,
  MidnightBloom = 103 , Crystalline = 104 , PartyBliss = 106 , ConfidentCloud = 107 ,
  LeCocktail = 108 , RiverCity = 109 , FrozenBerry = 110 , ChildCare = 112 ,
  FlyingLemon = 113 , NewRetrowave = 114 , HiddenJaguar = 115 , AboveTheSky = 116 ,
  Nega = 117 , DenseWater = 118 , Seashore = 120 , MarbleWall = 121 ,
  CheerfulCaramel = 122 , NightSky = 123 , MagicLake = 124 , YoungGrass = 125 ,
  ColorfulPeach = 126 , GentleCare = 127 , PlumBath = 128 , HappyUnicorn = 129 ,
  AfricanField = 131 , SolidStone = 132 , OrangeJuice = 133 , GlassWater = 134 ,
  NorthMiracle = 136 , FruitBlend = 137 , MillenniumPine = 138 , HighFlight = 139 ,
  MoleHall = 140 , SpaceShift = 142 , ForestInei = 143 , RoyalGarden = 144 ,
  RichMetal = 145 , JuicyCake = 146 , SmartIndigo = 147 , SandStrike = 148 ,
  NorseBeauty = 149 , AquaGuidance = 150 , SunVeggie = 151 , SeaLord = 152 ,
  BlackSea = 153 , GrassShampoo = 154 , LandingAircraft = 155 , WitchDance = 156 ,
  SleeplessNight = 157 , AngelCare = 158 , CrystalRiver = 159 , SoftLipstick = 160 ,
  SaltMountain = 161 , PerfectWhite = 162 , FreshOasis = 163 , StrictNovember = 164 ,
  MorningSalad = 165 , DeepRelief = 166 , SeaStrike = 167 , NightCall = 168 ,
  SupremeSky = 169 , LightBlue = 170 , MindCrawl = 171 , LilyMeadow = 172 ,
  SugarLollipop = 173 , SweetDessert = 174 , MagicRay = 175 , TeenParty = 176 ,
  FrozenHeat = 177 , GagarinView = 178 , FabledSunset = 179 , PerfectBlue = 180 ,
  NumPresets
}
 

Public Member Functions

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

Friends

class QLinearGradient
 
class QRadialGradient
 
class QConicalGradient
 
class QBrush
 

Related Functions

(Note that these are not member functions.)

 QGradientStop
 
 QGradientStops
 

Detailed Description

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

\inmodule QtGui

Qt currently supports three types of gradient fills:

\list

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

\table \header

The colors in a gradient are 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:

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:

It is possible to repeat or reflect the gradient outside its area by specifying the \l {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 \l {QGradient::Spread}{spread method} can be retrieved using the spread() function. The QGradient::Spread enum defines three different methods:

\table \row

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.

The gradient coordinates can be specified in logical coordinates, relative to device coordinates, or relative to object bounding box coordinates. The \l {QGradient::CoordinateMode}{coordinate mode} can be set using the setCoordinateMode() function. The default is LogicalMode, where the gradient coordinates are specified in the same way as the object coordinates. To retrieve the currently set \l {QGradient::CoordinateMode} {coordinate mode} use coordinateMode().

See also
{painting/gradients}{The Gradients Example}, QBrush

Definition at line 170 of file qbrush.h.

Member Enumeration Documentation

◆ CoordinateMode

Since
4.4

This enum specifies how gradient coordinates map to the paint device on which the gradient is used.

\value LogicalMode This is the default mode. The gradient coordinates are specified logical space just like the object coordinates. \value ObjectMode In this mode the gradient coordinates are relative to the bounding rectangle of the object being drawn, with (0,0) in the top left corner, and (1,1) in the bottom right corner of the object's bounding rectangle. This value was added in Qt 5.12. \value StretchToDeviceMode In this mode the gradient coordinates are relative to the bounding rectangle of the paint device, with (0,0) in the top left corner, and (1,1) in the bottom right corner of the paint device. \value ObjectBoundingMode This mode is the same as ObjectMode, except that the {QBrush::transform()} {brush transform}, if any, is applied relative to the logical space instead of the object space. This enum value is deprecated and should not be used in new code.

Enumerator
LogicalMode 
StretchToDeviceMode 
ObjectBoundingMode 
ObjectMode 

Definition at line 189 of file qbrush.h.

◆ InterpolationMode

Since
4.5
Enumerator
ColorInterpolation 
ComponentInterpolation 

Definition at line 197 of file qbrush.h.

◆ Preset

Since
5.12

This enum specifies a set of predefined presets for QGradient, based on the gradients from \l {https://webgradients.com/}.

\value WarmFlame \value NightFade \value SpringWarmth \value JuicyPeach \value YoungPassion \value LadyLips \value SunnyMorning \value RainyAshville \value FrozenDreams \value WinterNeva \value DustyGrass \value TemptingAzure \value HeavyRain \value AmyCrisp \value MeanFruit \value DeepBlue \value RipeMalinka \value CloudyKnoxville \value MalibuBeach \value NewLife \value TrueSunset \value MorpheusDen \value RareWind \value NearMoon \value WildApple \value SaintPetersburg \value PlumPlate \value EverlastingSky \value HappyFisher \value Blessing \value SharpeyeEagle \value LadogaBottom \value LemonGate \value ItmeoBranding \value ZeusMiracle \value OldHat \value StarWine \value HappyAcid \value AwesomePine \value NewYork \value ShyRainbow \value MixedHopes \value FlyHigh \value StrongBliss \value FreshMilk \value SnowAgain \value FebruaryInk \value KindSteel \value SoftGrass \value GrownEarly \value SharpBlues \value ShadyWater \value DirtyBeauty \value GreatWhale \value TeenNotebook \value PoliteRumors \value SweetPeriod \value WideMatrix \value SoftCherish \value RedSalvation \value BurningSpring \value NightParty \value SkyGlider \value HeavenPeach \value PurpleDivision \value AquaSplash \value SpikyNaga \value LoveKiss \value CleanMirror \value PremiumDark \value ColdEvening \value CochitiLake \value SummerGames \value PassionateBed \value MountainRock \value DesertHump \value JungleDay \value PhoenixStart \value OctoberSilence \value FarawayRiver \value AlchemistLab \value OverSun \value PremiumWhite \value MarsParty \value EternalConstance \value JapanBlush \value SmilingRain \value CloudyApple \value BigMango \value HealthyWater \value AmourAmour \value RiskyConcrete \value StrongStick \value ViciousStance \value PaloAlto \value HappyMemories \value MidnightBloom \value Crystalline \value PartyBliss \value ConfidentCloud \value LeCocktail \value RiverCity \value FrozenBerry \value ChildCare \value FlyingLemon \value NewRetrowave \value HiddenJaguar \value AboveTheSky \value Nega \value DenseWater \value Seashore \value MarbleWall \value CheerfulCaramel \value NightSky \value MagicLake \value YoungGrass \value ColorfulPeach \value GentleCare \value PlumBath \value HappyUnicorn \value AfricanField \value SolidStone \value OrangeJuice \value GlassWater \value NorthMiracle \value FruitBlend \value MillenniumPine \value HighFlight \value MoleHall \value SpaceShift \value ForestInei \value RoyalGarden \value RichMetal \value JuicyCake \value SmartIndigo \value SandStrike \value NorseBeauty \value AquaGuidance \value SunVeggie \value SeaLord \value BlackSea \value GrassShampoo \value LandingAircraft \value WitchDance \value SleeplessNight \value AngelCare \value CrystalRiver \value SoftLipstick \value SaltMountain \value PerfectWhite \value FreshOasis \value StrictNovember \value MorningSalad \value DeepRelief \value SeaStrike \value NightCall \value SupremeSky \value LightBlue \value MindCrawl \value LilyMeadow \value SugarLollipop \value SweetDessert \value MagicRay \value TeenParty \value FrozenHeat \value GagarinView \value FabledSunset \value PerfectBlue

Enumerator
WarmFlame 
NightFade 
SpringWarmth 
JuicyPeach 
YoungPassion 
LadyLips 
SunnyMorning 
RainyAshville 
FrozenDreams 
WinterNeva 
DustyGrass 
TemptingAzure 
HeavyRain 
AmyCrisp 
MeanFruit 
DeepBlue 
RipeMalinka 
CloudyKnoxville 
MalibuBeach 
NewLife 
TrueSunset 
MorpheusDen 
RareWind 
NearMoon 
WildApple 
SaintPetersburg 
PlumPlate 
EverlastingSky 
HappyFisher 
Blessing 
SharpeyeEagle 
LadogaBottom 
LemonGate 
ItmeoBranding 
ZeusMiracle 
OldHat 
StarWine 
HappyAcid 
AwesomePine 
NewYork 
ShyRainbow 
MixedHopes 
FlyHigh 
StrongBliss 
FreshMilk 
SnowAgain 
FebruaryInk 
KindSteel 
SoftGrass 
GrownEarly 
SharpBlues 
ShadyWater 
DirtyBeauty 
GreatWhale 
TeenNotebook 
PoliteRumors 
SweetPeriod 
WideMatrix 
SoftCherish 
RedSalvation 
BurningSpring 
NightParty 
SkyGlider 
HeavenPeach 
PurpleDivision 
AquaSplash 
SpikyNaga 
LoveKiss 
CleanMirror 
PremiumDark 
ColdEvening 
CochitiLake 
SummerGames 
PassionateBed 
MountainRock 
DesertHump 
JungleDay 
PhoenixStart 
OctoberSilence 
FarawayRiver 
AlchemistLab 
OverSun 
PremiumWhite 
MarsParty 
EternalConstance 
JapanBlush 
SmilingRain 
CloudyApple 
BigMango 
HealthyWater 
AmourAmour 
RiskyConcrete 
StrongStick 
ViciousStance 
PaloAlto 
HappyMemories 
MidnightBloom 
Crystalline 
PartyBliss 
ConfidentCloud 
LeCocktail 
RiverCity 
FrozenBerry 
ChildCare 
FlyingLemon 
NewRetrowave 
HiddenJaguar 
AboveTheSky 
Nega 
DenseWater 
Seashore 
MarbleWall 
CheerfulCaramel 
NightSky 
MagicLake 
YoungGrass 
ColorfulPeach 
GentleCare 
PlumBath 
HappyUnicorn 
AfricanField 
SolidStone 
OrangeJuice 
GlassWater 
NorthMiracle 
FruitBlend 
MillenniumPine 
HighFlight 
MoleHall 
SpaceShift 
ForestInei 
RoyalGarden 
RichMetal 
JuicyCake 
SmartIndigo 
SandStrike 
NorseBeauty 
AquaGuidance 
SunVeggie 
SeaLord 
BlackSea 
GrassShampoo 
LandingAircraft 
WitchDance 
SleeplessNight 
AngelCare 
CrystalRiver 
SoftLipstick 
SaltMountain 
PerfectWhite 
FreshOasis 
StrictNovember 
MorningSalad 
DeepRelief 
SeaStrike 
NightCall 
SupremeSky 
LightBlue 
MindCrawl 
LilyMeadow 
SugarLollipop 
SweetDessert 
MagicRay 
TeenParty 
FrozenHeat 
GagarinView 
FabledSunset 
PerfectBlue 
NumPresets 

Definition at line 202 of file qbrush.h.

◆ Spread

Specifies how the area outside the gradient area should be filled.

\value PadSpread The area is filled with the closest stop color. This is the default.

\value RepeatSpread The gradient is repeated outside the gradient area.

\value ReflectSpread The gradient is reflected outside the gradient area.

See also
spread(), setSpread()
Enumerator
PadSpread 
ReflectSpread 
RepeatSpread 

Definition at line 182 of file qbrush.h.

◆ Type

Specifies the type of gradient.

\value LinearGradient Interpolates colors between start and end points (QLinearGradient).

\value RadialGradient Interpolate colors between a focal point and end points on a circle surrounding it (QRadialGradient).

\value ConicalGradient Interpolate colors around a center point (QConicalGradient). \value NoGradient No gradient is used.

See also
type()
Enumerator
LinearGradient 
RadialGradient 
ConicalGradient 
NoGradient 

Definition at line 174 of file qbrush.h.

Constructor & Destructor Documentation

◆ QGradient() [1/2]

QGradient::QGradient ( )

Definition at line 1316 of file qbrush.cpp.

◆ QGradient() [2/2]

QGradient::QGradient ( QGradient::Preset  preset)
Since
5.12

Constructs a gradient based on a predefined preset.

The coordinate mode of the resulting gradient is QGradient::ObjectMode, allowing the preset to be applied to arbitrary object sizes.

Definition at line 1510 of file qbrush.cpp.

◆ ~QGradient()

QGradient::~QGradient ( )

Definition at line 1521 of file qbrush.cpp.

Member Function Documentation

◆ coordinateMode()

QGradient::CoordinateMode QGradient::coordinateMode ( ) const
Since
4.4

Returns the coordinate mode of this gradient. The default mode is LogicalMode.

Definition at line 1705 of file qbrush.cpp.

◆ interpolationMode()

QGradient::InterpolationMode QGradient::interpolationMode ( ) const
Since
4.5

Definition at line 1739 of file qbrush.cpp.

◆ operator!=()

bool QGradient::operator!= ( const QGradient gradient) const
inline
Since
4.2

Returns true if the gradient is the same as the other gradient specified; otherwise returns false.

See also
operator==()

Definition at line 397 of file qbrush.h.

Here is the call graph for this function:

◆ operator==()

bool QGradient::operator== ( const QGradient gradient) const

Returns true if the gradient is the same as the other gradient specified; otherwise returns false.

See also
operator!=()

Definition at line 1772 of file qbrush.cpp.

◆ setColorAt()

void QGradient::setColorAt ( qreal  position,
const QColor color 
)

Creates a stop point at the given position with the given color. The given position must be in the range 0 to 1.

See also
setStops(), stops()

Definition at line 1596 of file qbrush.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCoordinateMode()

void QGradient::setCoordinateMode ( CoordinateMode  mode)
Since
4.4

Sets the coordinate mode of this gradient to mode. The default mode is LogicalMode.

Definition at line 1716 of file qbrush.cpp.

Here is the caller graph for this function:

◆ setInterpolationMode()

void QGradient::setInterpolationMode ( InterpolationMode  mode)
Since
4.5

Definition at line 1751 of file qbrush.cpp.

Here is the caller graph for this function:

◆ setSpread()

void QGradient::setSpread ( Spread  method)
inline

Specifies the spread method that should be used for this gradient.

Note that this function only has effect for linear and radial gradients.

See also
spread()

Definition at line 426 of file qbrush.h.

Here is the caller graph for this function:

◆ setStops()

void QGradient::setStops ( const QGradientStops stopPoints)

Replaces the current set of stop points with the given stopPoints. The positions of the points must be in the range 0 to 1, and must be sorted with the lowest point first.

See also
setColorAt(), stops()

Definition at line 1641 of file qbrush.cpp.

Here is the caller graph for this function:

◆ spread()

QGradient::Spread QGradient::spread ( ) const
inline

Returns the spread method use by this gradient. The default is PadSpread.

See also
setSpread()

Definition at line 383 of file qbrush.h.

Here is the caller graph for this function:

◆ stops()

QGradientStops QGradient::stops ( ) const

Returns the stop points for this gradient.

If no stop points have been specified, a gradient of black at 0 to white at 1 is used.

See also
setStops(), setColorAt()

Definition at line 1664 of file qbrush.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type()

QGradient::Type QGradient::type ( ) const
inline

Returns the type of gradient.

Definition at line 380 of file qbrush.h.

Friends And Related Function Documentation

◆ QBrush

friend class QBrush
friend

Definition at line 416 of file qbrush.h.

◆ QConicalGradient

friend class QConicalGradient
friend

Definition at line 415 of file qbrush.h.

◆ QGradientStop()

QGradientStop
related

Typedef for QPair<\l qreal, QColor>.

Definition at line 167 of file qbrush.h.

Here is the caller graph for this function:

◆ QGradientStops()

QGradientStops
related

Typedef for QList<QGradientStop>.

Definition at line 168 of file qbrush.h.

◆ QLinearGradient

friend class QLinearGradient
friend

Definition at line 413 of file qbrush.h.

◆ QRadialGradient

friend class QRadialGradient
friend

Definition at line 414 of file qbrush.h.


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