QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QwtColorCycle Class Reference

Provides cyclic color selection from predefined palettes. More...

#include <qwt_color_cycle.h>

Public Types

enum  Palette {
  Default10 , Tab10 , Tab20 , Set1 ,
  Set2 , Set3 , OkabeIto
}
 Built-in color palettes. More...
 

Public Member Functions

 QwtColorCycle ()
 Construct with the Default10 palette (matplotlib classic)
 
 QwtColorCycle (Palette palette)
 Construct with a built-in palette.
 
 QwtColorCycle (const QVector< QColor > &colors)
 Construct with custom colors.
 
QColor color (int index) const
 Get a color by index (wraps around)
 
int count () const
 Get the number of colors in the cycle.
 
void setPalette (Palette)
 Set the palette from a built-in preset.
 
void setColors (const QVector< QColor > &)
 Set custom colors.
 
QVector< QColor > colors () const
 Get the current color list.
 

Static Public Member Functions

static QVector< QColor > paletteColors (Palette)
 Get the colors for a built-in palette.
 

Detailed Description

Provides cyclic color selection from predefined palettes.

QwtColorCycle manages an ordered list of colors and returns them in a cyclic manner using the color() method. This is used by QwtPlot to automatically assign distinct colors to plot items (curves, bar charts, etc.) when they are attached without a user-specified pen or brush.

Several built-in palettes are available, inspired by matplotlib, Tableau, ColorBrewer, and the Okabe-Ito colorblind-safe palette.

Example
QwtPlot plot;
auto* curve1 = new QwtPlotCurve("Series 1"); // gets color[0]
curve1->attach(&plot);
auto* curve2 = new QwtPlotCurve("Series 2"); // gets color[1]
curve2->attach(&plot);
@ OkabeIto
Okabe-Ito — 8 colorblind-safe colors.
Definition qwt_color_cycle.h:72
QwtColorCycle()
Construct with the Default10 palette (matplotlib classic)
Definition qwt_color_cycle.cpp:17
A plot item, that represents a series of points.
Definition qwt_plot_curve.h:75
A 2-D plotting widget.
Definition qwt_plot.h:99
void setColorCycle(const QwtColorCycle &)
Set the color cycle used for automatic item coloring.
Definition qwt_plot.cpp:1175
See also
QwtPlot::setColorCycle(), QwtPlot::colorCycle()

Member Enumeration Documentation

◆ Palette

Built-in color palettes.

Enumerator
Default10 

matplotlib classic 10 colors

Tab10 

Tableau Tab10 — high-contrast categorical colors.

Tab20 

Tableau Tab20 — 20 colors with light/dark pairs.

Set1 

ColorBrewer Set1 — 9 colors for qualitative data.

Set2 

ColorBrewer Set2 — 8 colors for qualitative data.

Set3 

ColorBrewer Set3 — 12 colors for qualitative data.

OkabeIto 

Okabe-Ito — 8 colorblind-safe colors.

Constructor & Destructor Documentation

◆ QwtColorCycle() [1/2]

QwtColorCycle::QwtColorCycle ( Palette  palette)
explicit

Construct with a built-in palette.

Parameters
paletteBuilt-in palette selector

◆ QwtColorCycle() [2/2]

QwtColorCycle::QwtColorCycle ( const QVector< QColor > &  colors)
explicit

Construct with custom colors.

Parameters
colorsCustom color list

Member Function Documentation

◆ color()

QColor QwtColorCycle::color ( int  index) const

Get a color by index (wraps around)

Get a color by index with cyclic wrap-around.

Parameters
indexZero-based index (negative values are handled)
Returns
Color at position (index % count)

◆ colors()

QVector< QColor > QwtColorCycle::colors ( ) const

Get the current color list.

Returns
Copy of the internal color list

◆ count()

int QwtColorCycle::count ( ) const

Get the number of colors in the cycle.

Returns
Number of colors

◆ paletteColors()

QVector< QColor > QwtColorCycle::paletteColors ( Palette  palette)
static

Get the colors for a built-in palette.

Get the color list for a built-in palette.

Parameters
paletteBuilt-in palette selector
Returns
Color list for the specified palette

◆ setColors()

void QwtColorCycle::setColors ( const QVector< QColor > &  colors)

Set custom colors.

Replace current colors with a custom list.

Parameters
colorsCustom color list

◆ setPalette()

void QwtColorCycle::setPalette ( Palette  palette)

Set the palette from a built-in preset.

Replace current colors with a built-in palette.

Parameters
paletteBuilt-in palette selector

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