![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtGui More...
#include <qbrush.h>
Classes | |
union | QGradientData |
Public Member Functions | |
QGradient () | |
QGradient (Preset) | |
~QGradient () | |
Type | type () const |
Returns the type of gradient. | |
void | setSpread (Spread spread) |
Specifies the spread method that should be used for this gradient. | |
Spread | spread () const |
Returns the spread method use by this gradient. | |
void | setColorAt (qreal pos, const QColor &color) |
Creates a stop point at the given position with the given color. | |
void | setStops (const QGradientStops &stops) |
Replaces the current set of stop points with the given stopPoints. | |
QGradientStops | stops () const |
Returns the stop points for this gradient. | |
CoordinateMode | coordinateMode () const |
void | setCoordinateMode (CoordinateMode mode) |
InterpolationMode | interpolationMode () const |
void | setInterpolationMode (InterpolationMode mode) |
bool | operator== (const QGradient &gradient) const |
Returns true if the gradient is the same as the other gradient specified; otherwise returns false . | |
bool | operator!= (const QGradient &other) const |
Friends | |
class | QLinearGradient |
class | QRadialGradient |
class | QConicalGradient |
class | QBrush |
Related Symbols | |
(Note that these are not member symbols.) | |
QGradientStop | |
Typedef for QPair<\l qreal, QColor>. | |
QGradientStops | |
Typedef for QList<QGradientStop>. | |
\inmodule QtGui
The QGradient class is used in combination with QBrush to specify gradient fills.
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().
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 |
enum QGradient::Preset |
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
enum QGradient::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.
Enumerator | |
---|---|
PadSpread | |
ReflectSpread | |
RepeatSpread |
enum QGradient::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.
Enumerator | |
---|---|
LinearGradient | |
RadialGradient | |
ConicalGradient | |
NoGradient |
QGradient::QGradient | ( | ) |
Definition at line 1283 of file qbrush.cpp.
QGradient::QGradient | ( | QGradient::Preset | preset | ) |
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 1477 of file qbrush.cpp.
QGradient::~QGradient | ( | ) |
Definition at line 1488 of file qbrush.cpp.
QGradient::CoordinateMode QGradient::coordinateMode | ( | ) | const |
Returns the coordinate mode of this gradient. The default mode is LogicalMode.
Definition at line 1672 of file qbrush.cpp.
Referenced by needsEmulation(), QBrush::operator<<(), and QSvgPaintEngine::saveGradientUnits().
QGradient::InterpolationMode QGradient::interpolationMode | ( | ) | const |
Returns the interpolation mode of this gradient. The default mode is ColorInterpolation.
Definition at line 1706 of file qbrush.cpp.
Referenced by QGradientCache::addCacheElement(), QGradientCache::generateGradientColorTable(), QGradientCache::getBuffer(), QOpenGL2GradientCache::getBuffer(), and QBrush::operator<<().
|
inline |
Returns true
if the gradient is the same as the other gradient specified; otherwise returns false
.
Definition at line 361 of file qbrush.h.
References operator==(), and other().
bool QGradient::operator== | ( | const QGradient & | gradient | ) | const |
Returns true
if the gradient is the same as the other gradient specified; otherwise returns false
.
Definition at line 1739 of file qbrush.cpp.
References QGradient::QGradientData::angle, QGradient::QGradientData::conical, QGradient::QGradientData::cradius, QGradient::QGradientData::cx, QGradient::QGradientData::cy, QGradient::QGradientData::fradius, QGradient::QGradientData::fx, QGradient::QGradientData::fy, QGradient::QGradientData::linear, LinearGradient, QGradient::QGradientData::radial, RadialGradient, stops(), QGradient::QGradientData::x1, QGradient::QGradientData::x2, QGradient::QGradientData::y1, and QGradient::QGradientData::y2.
Creates a stop point at the given position with the given color.
The given position must be in the range 0 to 1.
Definition at line 1563 of file qbrush.cpp.
References QList< T >::at(), QList< T >::insert(), pos, QGradientStop(), qIsNaN(), qWarning, and QList< T >::size().
Referenced by QAndroidStyle::AndroidGradientDrawable::AndroidGradientDrawable(), SplitterHandle::SplitterHandle(), QQC2::QCommonStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QWindowsVistaStyle::drawControl(), QQC2::QStyleHelper::drawDial(), QQuickContext2DStyle::gradient_proto_addColorStop(), QQuickFusionBusyIndicator::paint(), QQuickFusionDial::paint(), QQuickFusionKnob::paint(), QtPrivate::PageItem::paint(), parseStopNode(), setStops(), titlebarGradientActive(), QQC2_NAMESPACE::titlebarGradientActive(), titlebarGradientInactive(), QQC2_NAMESPACE::titlebarGradientInactive(), brush::wrapper(), and gradientcreationsnippet::wrapper().
void QGradient::setCoordinateMode | ( | CoordinateMode | mode | ) |
Sets the coordinate mode of this gradient to mode. The default mode is LogicalMode.
Definition at line 1683 of file qbrush.cpp.
Referenced by QBrush::operator>>(), parseBaseGradient(), and parseBrushValue().
void QGradient::setInterpolationMode | ( | InterpolationMode | mode | ) |
Sets the interpolation mode of this gradient to mode. The default mode is ColorInterpolation.
Definition at line 1718 of file qbrush.cpp.
Referenced by createLinearGradientNode(), createRadialGradientNode(), and QBrush::operator>>().
Specifies the spread method that should be used for this gradient.
Note that this function only has effect for linear and radial gradients.
Definition at line 390 of file qbrush.h.
Referenced by QBrush::operator>>(), parseBaseGradient(), parseBrushValue(), and setupPainterGradient().
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.
Definition at line 1608 of file qbrush.cpp.
References QList< T >::at(), QList< T >::clear(), i, ok, Q_LIKELY, setColorAt(), QList< T >::size(), and stops().
Referenced by QSvgGradientStyle::brush(), QBrush::operator>>(), parseBaseGradient(), parseBrushValue(), parseStopNode(), QSvgGradientStyle::resolveStops_helper(), setupPainterGradient(), and QSGSoftwareInternalRectangleNode::update().
|
inline |
Returns the spread method use by this gradient.
The default is PadSpread.
Definition at line 347 of file qbrush.h.
Referenced by QBrush::operator<<(), QCoreGraphicsPaintEnginePrivate::setFillBrush(), QWindowsDirect2DPaintEnginePrivate::to_d2d_brush(), and QOpenGL2PaintEngineExPrivate::updateBrushTexture().
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.
Definition at line 1631 of file qbrush.cpp.
References QColorConstants::Black, QList< QGradientStop >::fromReadOnlyData(), QList< T >::isEmpty(), and QColorConstants::White.
Referenced by QGradientCache::addCacheElement(), QGradientCache::generateGradientColorTable(), QGradientCache::getBuffer(), QOpenGL2GradientCache::getBuffer(), QBrush::isOpaque(), QBrush::operator<<(), operator==(), parseBaseGradient(), parseStopNode(), QSvgGradientStyle::resolveStops_helper(), and setStops().
|
inline |
Returns the type of gradient.
Definition at line 344 of file qbrush.h.
Referenced by QBrush::QBrush(), QBrush::operator<<(), QOpenGL2PaintEngineExPrivate::updateBrushTexture(), and QQuickRectangle::updatePaintNode().
|
friend |
|
related |
Typedef for QPair<\l qreal, QColor>.
Definition at line 131 of file qbrush.h.
Referenced by setColorAt().
|
related |
Typedef for QList<QGradientStop>.
|
friend |
|
friend |