QGraphsTheme Class

QGraphsTheme class provides a visual style for graphs. More...

Header: #include <QGraphsTheme>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
In QML: GraphsTheme
Inherits: QObject and QQmlParserStatus

Public Types

enum class ColorStyle { Uniform, ObjectGradient, RangeGradient }
enum class Theme { QtGreen, QtGreenNeon, MixSeries, OrangeSeries, YellowSeries, …, UserDefined }

Properties

Public Functions

QColor axisXLabelColor() const
QFont axisXLabelFont() const
QColor axisXMainColor() const
qreal axisXMainWidth() const
QColor axisXSubColor() const
qreal axisXSubWidth() const
QColor axisYLabelColor() const
QFont axisYLabelFont() const
QColor axisYMainColor() const
qreal axisYMainWidth() const
QColor axisYSubColor() const
qreal axisYSubWidth() const
QColor axisZLabelColor() const
QFont axisZLabelFont() const
QColor axisZMainColor() const
qreal axisZMainWidth() const
QColor axisZSubColor() const
qreal axisZSubWidth() const
QColor backgroundColor() const
QList<QColor> borderColors() const
qreal borderWidth() const
Qt::ColorScheme colorScheme() const
QGraphsTheme::ColorStyle colorStyle() const
QColor gridMainColor() const
qreal gridMainWidth() const
QColor gridSubColor() const
qreal gridSubWidth() const
bool isBackgroundVisible() const
bool isGridVisible() const
bool isLabelBackgroundVisible() const
bool isLabelBorderVisible() const
bool isPlotAreaBackgroundVisible() const
QColor labelBackgroundColor() const
QFont labelFont() const
QColor labelTextColor() const
bool labelsVisible() const
QColor multiHighlightColor() const
QColor plotAreaBackgroundColor() const
QList<QColor> seriesColors() const
QList<QLinearGradient> seriesGradients() const
void setAxisXLabelColor(const QColor &newAxisXLabelColor)
void setAxisXLabelFont(const QFont &newAxisXLabelFont)
void setAxisXMainColor(const QColor &newAxisXMainColor)
void setAxisXMainWidth(qreal newAxisXMainWidth)
void setAxisXSubColor(const QColor &newAxisXSubColor)
void setAxisXSubWidth(qreal newAxisXSubWidth)
void setAxisYLabelColor(const QColor &newAxisYLabelColor)
void setAxisYLabelFont(const QFont &newAxisYLabelFont)
void setAxisYMainColor(const QColor &newAxisYMainColor)
void setAxisYMainWidth(qreal newAxisYMainWidth)
void setAxisYSubColor(const QColor &newAxisYSubColor)
void setAxisYSubWidth(qreal newAxisYSubWidth)
void setAxisZLabelColor(const QColor &newAxisZLabelColor)
void setAxisZLabelFont(const QFont &newAxisZLabelFont)
void setAxisZMainColor(const QColor &newAxisZMainColor)
void setAxisZMainWidth(qreal newAxisZMainWidth)
void setAxisZSubColor(const QColor &newAxisZSubColor)
void setAxisZSubWidth(qreal newAxisZSubWidth)
void setBackgroundColor(const QColor &newBackgroundColor)
void setBackgroundVisible(bool newBackgroundVisible)
void setBorderColors(const QList<QColor> &newBorderColors)
void setBorderWidth(qreal newBorderWidth)
void setColorScheme(Qt::ColorScheme newColorScheme)
void setColorStyle(QGraphsTheme::ColorStyle newColorStyle)
void setGridMainColor(const QColor &newgridMainColor)
void setGridMainWidth(qreal newgridMainWidth)
void setGridSubColor(const QColor &newgridSubColor)
void setGridSubWidth(qreal newgridSubWidth)
void setGridVisible(bool newGridVisibility)
void setLabelBackgroundColor(const QColor &newLabelBackgroundColor)
void setLabelBackgroundVisible(bool newLabelBackgroundVisibility)
void setLabelBorderVisible(bool newLabelBorderVisibility)
void setLabelFont(const QFont &newFont)
void setLabelTextColor(const QColor &newLabelTextColor)
void setLabelsVisible(bool newLabelsVisibility)
void setMultiHighlightColor(const QColor &newMultiHighlightColor)
void setMultiHighlightGradient(const QLinearGradient &gradient)
void setPlotAreaBackgroundColor(const QColor &newBackgroundColor)
void setPlotAreaBackgroundVisible(bool newBackgroundVisibility)
void setSeriesColors(const QList<QColor> &newSeriesColors)
void setSeriesGradients(const QList<QLinearGradient> &newSeriesGradients)
void setSingleHighlightColor(const QColor &newSingleHighlightColor)
void setSingleHighlightGradient(const QLinearGradient &gradient)
void setTheme(QGraphsTheme::Theme newTheme, bool force = false)
QColor singleHighlightColor() const
QGraphsTheme::Theme theme() const

Signals

Detailed Description

Specifies visual properties that affect the whole graph. There are several built-in themes that can be used as is or modified freely.

Themes can be created from scratch using the UserDefined enum value. Creating a theme using the default constructor produces a new user-defined theme.

Default Theme

The following table lists the properties controlled by themes and the default values for UserDefined.

Usage Examples

Creating a built-in theme without any modifications:

 QGraphsTheme *theme = new QGraphsTheme();

Creating a built-in theme and modifying some properties:

 QGraphsTheme *theme = new QGraphsTheme();
 theme->setBackgroundVisible(false);
 theme->setLabelBackgroundVisible(false);

Creating a user-defined theme:

 QGraphsTheme *theme = new QGraphsTheme();
 theme->setBackgroundColor(QColor(QRgb(0x99ca53)));
 theme->setBackgroundVisible(true);
 QList<QColor> colors = { QColor(QRgb(0x209fdf)) };
 theme->setSeriesColors(colors);
 theme->setColorStyle(QGraphsTheme::ColorStyle::Uniform);
 theme->setLabelFont(QFont(QStringLiteral("Impact"), 35));
 theme->setGridVisible(true);
 theme->setGridMainColor(QColor(QRgb(0x99ca53)));
 theme->setLabelBackgroundColor(QColor(0xf6, 0xa6, 0x25, 0xa0));
 theme->setLabelBackgroundVisible(true);
 theme->setLabelBorderVisible(true);
 theme->setLabelTextColor(QColor(QRgb(0x404044)));
 theme->setMultiHighlightColor(QColor(QRgb(0x6d5fd5)));
 theme->setSingleHighlightColor(QColor(QRgb(0xf6a625)));
 theme->setWindowColor(QColor(QRgb(0xffffff)));

Creating a built-in theme and modifying some properties after it has been set:

 Q3DBars *graph = new Q3DBars();
 graph->activeTheme()->setTheme(QGraphsTheme::Theme::MixSeries);
 QList<QColor> color = { QColor(Qt::red) };
 graph->activeTheme()->setSeriesColors(color);
 graph->activeTheme()->setSingleHighlightColor(Qt::yellow);

Member Type Documentation

enum class QGraphsTheme::ColorStyle

Gradient types.

ConstantValueDescription
QGraphsTheme::ColorStyle::Uniform0Objects are rendered in a single color. The color used is specified in seriesColors, singleHighlightColor and multiHighlightColor properties.
QGraphsTheme::ColorStyle::ObjectGradient1Objects are colored using a full gradient for each object regardless of object height. The gradient used is specified in seriesGradients, singleHighlightGradient and multiHighlightGradient properties.
QGraphsTheme::ColorStyle::RangeGradient2Objects are colored using a portion of the full gradient determined by the object's height and its position on the Y-axis. The gradient used is specified in seriesGradients, singleHighlightGradient and multiHighlightGradient properties.

enum class QGraphsTheme::Theme

Built-in themes.

ConstantValueDescription
QGraphsTheme::Theme::QtGreen0A light theme with green as the base color.
QGraphsTheme::Theme::QtGreenNeon1A light theme with green neon as the base color.
QGraphsTheme::Theme::MixSeries2A mixed theme with various colors.
QGraphsTheme::Theme::OrangeSeries3A theme with Orange as the base color.
QGraphsTheme::Theme::YellowSeries4A theme with Yellow as the base color.
QGraphsTheme::Theme::BlueSeries5A theme with Blue as the base color.
QGraphsTheme::Theme::PurpleSeries6A theme with Purple as the base color.
QGraphsTheme::Theme::GreySeries7A theme with Grey as the base color.
QGraphsTheme::Theme::UserDefined8A user-defined theme. For more information, see Default Theme.

Property Documentation

axisXLabelColor : QColor

This property holds the text color to be used for labels on x axis The default value depends on colorScheme.

Access functions:

QColor axisXLabelColor() const
void setAxisXLabelColor(const QColor &newAxisXLabelColor)

Notifier signal:

void axisXLabelColorChanged()

axisXLabelFont : QFont

This property holds the font to be used for labels on x axis.

Access functions:

QFont axisXLabelFont() const
void setAxisXLabelFont(const QFont &newAxisXLabelFont)

Notifier signal:

void axisXLabelFontChanged()

axisXMainColor : QColor

This property holds the color of the x axis main lines. The default value depends on colorScheme.

Access functions:

QColor axisXMainColor() const
void setAxisXMainColor(const QColor &newAxisXMainColor)

Notifier signal:

void axisXMainColorChanged()

axisXMainWidth : qreal

This property holds the width of the x axis main lines. The default value is 2.0.

Access functions:

qreal axisXMainWidth() const
void setAxisXMainWidth(qreal newAxisXMainWidth)

Notifier signal:

void axisXMainWidthChanged()

axisXSubColor : QColor

This property holds the color of the x axis sub lines. The default value depends on colorScheme.

Access functions:

QColor axisXSubColor() const
void setAxisXSubColor(const QColor &newAxisXSubColor)

Notifier signal:

void axisXSubColorChanged()

axisXSubWidth : qreal

This property holds the width of the x axis sub lines. The default value is 1.0.

Access functions:

qreal axisXSubWidth() const
void setAxisXSubWidth(qreal newAxisXSubWidth)

Notifier signal:

void axisXSubWidthChanged()

axisYLabelColor : QColor

This property holds the text color to be used for labels on y axis The default value depends on colorScheme.

Access functions:

QColor axisYLabelColor() const
void setAxisYLabelColor(const QColor &newAxisYLabelColor)

Notifier signal:

void axisYLabelColorChanged()

axisYLabelFont : QFont

This property holds the font to be used for labels on y axis.

Access functions:

QFont axisYLabelFont() const
void setAxisYLabelFont(const QFont &newAxisYLabelFont)

Notifier signal:

void axisYLabelFontChanged()

axisYMainColor : QColor

This property holds the color of the y axis main lines. The default value depends on colorScheme.

Access functions:

QColor axisYMainColor() const
void setAxisYMainColor(const QColor &newAxisYMainColor)

Notifier signal:

void axisYMainColorChanged()

axisYMainWidth : qreal

This property holds the width of the y axis main lines. The default value is 2.0.

Access functions:

qreal axisYMainWidth() const
void setAxisYMainWidth(qreal newAxisYMainWidth)

Notifier signal:

void axisYMainWidthChanged()

axisYSubColor : QColor

This property holds the color of the y axis sub lines. The default value depends on colorScheme.

Access functions:

QColor axisYSubColor() const
void setAxisYSubColor(const QColor &newAxisYSubColor)

Notifier signal:

void axisYSubColorChanged()

axisYSubWidth : qreal

This property holds the width of the y axis sub lines. The default value is 1.0.

Access functions:

qreal axisYSubWidth() const
void setAxisYSubWidth(qreal newAxisYSubWidth)

Notifier signal:

void axisYSubWidthChanged()

axisZLabelColor : QColor

This property holds the text color to be used for labels on z axis The default value depends on colorScheme.

Access functions:

QColor axisZLabelColor() const
void setAxisZLabelColor(const QColor &newAxisZLabelColor)

Notifier signal:

void axisZLabelColorChanged()

axisZLabelFont : QFont

This property holds the font to be used for labels on z axis.

Access functions:

QFont axisZLabelFont() const
void setAxisZLabelFont(const QFont &newAxisZLabelFont)

Notifier signal:

void axisZLabelFontChanged()

axisZMainColor : QColor

This property holds the color of the z axis main lines. The default value depends on colorScheme.

Access functions:

QColor axisZMainColor() const
void setAxisZMainColor(const QColor &newAxisZMainColor)

Notifier signal:

void axisZMainColorChanged()

axisZMainWidth : qreal

This property holds the width of the z axis main lines. The default value is 2.0.

Access functions:

qreal axisZMainWidth() const
void setAxisZMainWidth(qreal newAxisZMainWidth)

Notifier signal:

void axisZMainWidthChanged()

axisZSubColor : QColor

This property holds the color of the z axis sub lines. The default value depends on colorScheme.

Access functions:

QColor axisZSubColor() const
void setAxisZSubColor(const QColor &newAxisZSubColor)

Notifier signal:

void axisZSubColorChanged()

axisZSubWidth : qreal

This property holds the width of the z axis sub lines. The default value is 1.0.

Access functions:

qreal axisZSubWidth() const
void setAxisZSubWidth(qreal newAxisZSubWidth)

Notifier signal:

void axisZSubWidthChanged()

backgroundColor : QColor

This property holds the color of the view the graph is drawn into. The default value depends on colorScheme.

Access functions:

QColor backgroundColor() const
void setBackgroundColor(const QColor &newBackgroundColor)

Notifier signal:

void backgroundColorChanged()

backgroundVisible : bool

This property holds whether the background is visible.

The background is drawn by using the value of backgroundColor. The default value is true.

Access functions:

bool isBackgroundVisible() const
void setBackgroundVisible(bool newBackgroundVisible)

Notifier signal:

void backgroundVisibleChanged()

borderColors : QList<QColor>

This property holds the list of border colors to be used for all the objects in the graph, series by series.

If there are more series than colors, the color list wraps and starts again with the first color in the list.

Has no immediate effect if colorStyle is not Uniform.

Access functions:

QList<QColor> borderColors() const
void setBorderColors(const QList<QColor> &newBorderColors)

Notifier signal:

void borderColorsChanged()

borderWidth : qreal

This property holds the width of borders in graph if any The default value is 1.0.

Access functions:

qreal borderWidth() const
void setBorderWidth(qreal newBorderWidth)

Notifier signal:

void borderWidthChanged()

colorScheme : Qt::ColorScheme

The color scheme of the graph in use.

Access functions:

Qt::ColorScheme colorScheme() const
void setColorScheme(Qt::ColorScheme newColorScheme)

Notifier signal:

void colorSchemeChanged()

See also Qt::ColorScheme.

colorStyle : ColorStyle

The style of the graph colors. One of QGraphsTheme::ColorStyle enum values.

This value can be overridden by setting Abstract3DSeries.colorStyle explicitly in the series.

Note: This property does not have an effect in Qt Graphs for 2D.

Access functions:

QGraphsTheme::ColorStyle colorStyle() const
void setColorStyle(QGraphsTheme::ColorStyle newColorStyle)

Notifier signal:

void colorStyleChanged(QGraphsTheme::ColorStyle type)

See also QGraphsTheme::ColorStyle.

gridMainColor : QColor

This property holds the color of the main grid lines. The default value depends on colorScheme.

Access functions:

QColor gridMainColor() const
void setGridMainColor(const QColor &newgridMainColor)

Notifier signal:

void gridMainColorChanged()

gridMainWidth : qreal

This property holds the width of the main grid lines. The default value is 2.0.

Access functions:

qreal gridMainWidth() const
void setGridMainWidth(qreal newgridMainWidth)

Notifier signal:

void gridMainWidthChanged()

gridSubColor : QColor

This property holds the color of the subgrid lines. The default value depends on colorScheme.

Access functions:

QColor gridSubColor() const
void setGridSubColor(const QColor &newgridSubColor)

Notifier signal:

void gridSubColorChanged()

gridSubWidth : qreal

This property holds the width of the subgrid lines. The default value is 1.0.

Access functions:

qreal gridSubWidth() const
void setGridSubWidth(qreal newgridSubWidth)

Notifier signal:

void gridSubWidthChanged()

gridVisible : bool

This property holds whether the grid lines are drawn.

This value affects all grid lines. The default value is true.

Access functions:

bool isGridVisible() const
void setGridVisible(bool newGridVisibility)

Notifier signal:

void gridVisibleChanged()

labelBackgroundColor : QColor

This property holds the color of the label backgrounds.

Has no effect if labelBackgroundVisible is false. The default value depends on colorScheme.

Access functions:

QColor labelBackgroundColor() const
void setLabelBackgroundColor(const QColor &newLabelBackgroundColor)

Notifier signal:

void labelBackgroundColorChanged()

labelBackgroundVisible : bool

This property holds whether the label is drawn with a color background or with a fully transparent background.

The labelBackgroundColor value (including alpha) is used for drawing the background.

Labels with a background are drawn to equal sizes per axis based on the longest label, and the text is centered in them. Labels without a background are drawn as is and are left or right aligned based on their position in the graph. The default value is true.

Access functions:

bool isLabelBackgroundVisible() const
void setLabelBackgroundVisible(bool newLabelBackgroundVisibility)

Notifier signal:

void labelBackgroundVisibleChanged()

labelBorderVisible : bool

This property holds whether label borders are drawn for labels that have a background.

Has no effect if labelBackgroundVisible is false. The default value is true.

Access functions:

bool isLabelBorderVisible() const
void setLabelBorderVisible(bool newLabelBorderVisibility)

Notifier signal:

void labelBorderVisibleChanged()

labelFont : QFont

This property holds the font to be used for labels.

Access functions:

QFont labelFont() const
void setLabelFont(const QFont &newFont)

Notifier signal:

void labelFontChanged()

labelTextColor : QColor

This property holds the color of the font used for labels. The default value depends on colorScheme.

Access functions:

QColor labelTextColor() const
void setLabelTextColor(const QColor &newLabelTextColor)

Notifier signal:

void labelTextColorChanged()

labelsVisible : bool

This property holds whether labels are drawn at all.

If this is false, all other label properties have no effect. The default value is true.

Access functions:

bool labelsVisible() const
void setLabelsVisible(bool newLabelsVisibility)

Notifier signal:

void labelsVisibleChanged()

multiHighlightColor : QColor

This property holds the highlight color for selected objects.

Used if selectionMode has the QGraphs3D::SelectionFlag::Row or QGraphs3D::SelectionFlag::Column flag set. The default value depends on colorScheme.

Access functions:

QColor multiHighlightColor() const
void setMultiHighlightColor(const QColor &newMultiHighlightColor)

Notifier signal:

void multiHighlightColorChanged()

multiHighlightGradient : QJSValue

This property holds the highlight gradient for selected objects.

Used if selectionMode has the QGraphs3D::SelectionFlag::Row or QGraphs3D::SelectionFlag::Column flag set. The default value depends on colorScheme.

Access functions:

void setMultiHighlightGradient(const QLinearGradient &gradient)

Notifier signal:

void multiHighlightGradientQMLChanged()

plotAreaBackgroundColor : QColor

This property holds the color of the graph plot area background. The default value depends on colorScheme.

Access functions:

QColor plotAreaBackgroundColor() const
void setPlotAreaBackgroundColor(const QColor &newBackgroundColor)

Notifier signal:

void plotAreaBackgroundColorChanged()

plotAreaBackgroundVisible : bool

This property holds whether the plot area background is visible.

The background is drawn by using the value of plotAreaBackgroundColor. The default value is true.

Access functions:

bool isPlotAreaBackgroundVisible() const
void setPlotAreaBackgroundVisible(bool newBackgroundVisibility)

Notifier signal:

void plotAreaBackgroundVisibleChanged()

seriesColors : QList<QColor>

This property holds the list of base colors to be used for all the objects in the graph, series by series.

If there are more series than colors, the color list wraps and starts again with the first color in the list.

Has no immediate effect if colorStyle is not Uniform.

This value can be overridden by setting the baseColor explicitly in the series.

Access functions:

QList<QColor> seriesColors() const
void setSeriesColors(const QList<QColor> &newSeriesColors)

Notifier signal:

void seriesColorsChanged(const QList<QColor> &list)

seriesGradients : QList<QLinearGradient>

This property holds the list of base gradients to be used for all the objects in the graph, series by series.

If there are more series than gradients, the gradient list wraps and starts again with the first gradient in the list

Has no immediate effect if colorStyle is Uniform.

This value can be overridden by setting the baseGradient explicitly in the series.

Access functions:

QList<QLinearGradient> seriesGradients() const
void setSeriesGradients(const QList<QLinearGradient> &newSeriesGradients)

Notifier signal:

void seriesGradientsChanged(const QList<QLinearGradient> &list)

singleHighlightColor : QColor

This property holds the highlight color for a selected object.

Used if selectionMode has the QGraphs3D::SelectionFlag::Item flag set. The default value depends on colorScheme.

Access functions:

QColor singleHighlightColor() const
void setSingleHighlightColor(const QColor &newSingleHighlightColor)

Notifier signal:

void singleHighlightColorChanged()

singleHighlightGradient : QJSValue

This property holds the highlight gradient for a selected object.

Used if selectionMode has the QGraphs3D::SelectionFlag::Item flag set. The default value depends on colorScheme.

Access functions:

void setSingleHighlightGradient(const QLinearGradient &gradient)

Notifier signal:

void singleHighlightGradientQMLChanged()

theme : Theme

The type of the theme. If no type is set, the type is GraphsTheme.Theme.UserDefined. Changing the theme type after the item has been constructed will change all other properties of the theme to what the predefined theme specifies. Changing the theme type of the active theme of the graph will also reset all attached series to use the new theme.

Access functions:

QGraphsTheme::Theme theme() const
void setTheme(QGraphsTheme::Theme newTheme, bool force = false)

Notifier signal:

void themeChanged(QGraphsTheme::Theme theme)