Q3DTheme 类

Q3DTheme 类为图形提供视觉样式。 更多...

头: #include <Q3DTheme>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
实例化: Theme3D
继承: QObject and QQmlParserStatus
状态: 技术预览

公共类型

enum class ColorStyle { Uniform, ObjectGradient, RangeGradient }
enum class Theme { Qt, PrimaryColors, StoneMoss, ArmyBlue, Retro, …, UserDefined }

特性

公共函数

Q3DTheme (QObject * parent = nullptr)
Q3DTheme (Q3DTheme::Theme themeType , QObject * parent = nullptr)
virtual ~Q3DTheme () override
float ambientLightStrength () const
QColor backgroundColor () const
Q3DTheme::ColorStyle colorStyle () const
QFont font () const
QColor gridLineColor () const
bool isBackgroundEnabled () const
bool isGridEnabled () const
bool isLabelBackgroundEnabled () const
bool isLabelBorderEnabled () const
bool isLabelsEnabled () const
QColor labelBackgroundColor () const
QColor labelTextColor () const
QColor lightColor () const
float lightStrength () const
QColor multiHighlightColor () const
void setAmbientLightStrength (float strength )
void setBackgroundColor (const QColor & color )
void setBackgroundEnabled (bool enabled )
void setColorStyle (Q3DTheme::ColorStyle style )
void setFont (const QFont & font )
void setGridEnabled (bool enabled )
void setGridLineColor (const QColor & color )
void setLabelBackgroundColor (const QColor & color )
void setLabelBackgroundEnabled (bool enabled )
void setLabelBorderEnabled (bool enabled )
void setLabelTextColor (const QColor & color )
void setLabelsEnabled (bool enabled )
void setLightColor (const QColor & color )
void setLightStrength (float strength )
void setMultiHighlightColor (const QColor & color )
void setMultiHighlightGradient (const QLinearGradient & gradient )
void setShadowStrength (float strength )
void setSingleHighlightColor (const QColor & color )
void setSingleHighlightGradient (const QLinearGradient & gradient )
void setType (Q3DTheme::Theme themeType )
void setWindowColor (const QColor & color )
float shadowStrength () const
QColor singleHighlightColor () const
Q3DTheme::Theme type () const
QColor windowColor () const

信号

void ambientLightStrengthChanged (float strength )
void backgroundColorChanged (const QColor & color )
void backgroundEnabledChanged (bool enabled )
void colorStyleChanged (Q3DTheme::ColorStyle style )
void fontChanged (const QFont & font )
void gridEnabledChanged (bool enabled )
void gridLineColorChanged (const QColor & color )
void labelBackgroundColorChanged (const QColor & color )
void labelBackgroundEnabledChanged (bool enabled )
void labelBorderEnabledChanged (bool enabled )
void labelTextColorChanged (const QColor & color )
void labelsEnabledChanged (bool enabled )
void lightColorChanged (const QColor & color )
void lightStrengthChanged (float strength )
void multiHighlightColorChanged (const QColor & color )
void multiHighlightGradientChangedQML (QJSValue gradient )
void shadowStrengthChanged (float strength )
void singleHighlightColorChanged (const QColor & color )
void singleHighlightGradientQMLChanged (QJSValue gradient )
void typeChanged (Q3DTheme::Theme themeType )
void windowColorChanged (const QColor & color )

详细描述

指定影响整个图形的视觉特性。有几个内置主题可以使用或自由修改。

可以覆写以下特性通过使用 QAbstract3DSeries 特性以按系列明确设置它们: baseColors , baseGradients ,和 colorStyle .

可以从新创建主题使用 UserDefined 枚举值。使用默认构造函数创建主题会产生新的用户定义主题。

默认主题

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

特性 默认值
ambientLightStrength 0.25
backgroundColor Qt::black
backgroundEnabled true
baseColors Qt::black
baseGradients QLinearGradient 。本质上全黑。
colorStyle Uniform
font QFont
gridEnabled true
gridLineColor Qt::white
labelBackgroundColor Qt::gray
labelBackgroundEnabled true
labelBorderEnabled true
labelTextColor Qt::white
labelsEnabled true
lightColor Qt::white
lightStrength 5.0
multiHighlightColor Qt::blue
multiHighlightGradient QLinearGradient 。本质上全黑。
shadowStrength 25.0
singleHighlightColor Qt::red
singleHighlightGradient QLinearGradient 。本质上全黑。
windowColor Qt::black

用法范例

创建内置主题不做任何修改:

Q3DTheme *theme = new Q3DTheme(Q3DTheme::Theme::Qt);
					

创建内置主题并修改一些特性:

Q3DTheme *theme = new Q3DTheme(Q3DTheme::Theme::Qt);
theme->setBackgroundEnabled(false);
theme->setLabelBackgroundEnabled(false);
					

创建用户定义主题:

Q3DTheme *theme = new Q3DTheme();
theme->setAmbientLightStrength(0.3f);
theme->setBackgroundColor(QColor(QRgb(0x99ca53)));
theme->setBackgroundEnabled(true);
QList<QColor> colors = { QColor(QRgb(0x209fdf)) };
theme->setBaseColors(colors);
theme->setColorStyle(Q3DTheme::ColorStyle::Uniform);
theme->setFont(QFont(QStringLiteral("Impact"), 35));
theme->setGridEnabled(true);
theme->setGridLineColor(QColor(QRgb(0x99ca53)));
theme->setLabelBackgroundColor(QColor(0xf6, 0xa6, 0x25, 0xa0));
theme->setLabelBackgroundEnabled(true);
theme->setLabelBorderEnabled(true);
theme->setLabelTextColor(QColor(QRgb(0x404044)));
theme->setLightColor(Qt::white);
theme->setLightStrength(6.0f);
theme->setMultiHighlightColor(QColor(QRgb(0x6d5fd5)));
theme->setSingleHighlightColor(QColor(QRgb(0xf6a625)));
theme->setWindowColor(QColor(QRgb(0xffffff)));
					

创建内置主题并在设置后修改一些特性:

Q3DBars *graph = new Q3DBars();
graph->activeTheme()->setType(Q3DTheme::Theme::PrimaryColors);
QList<QColor> color = { QColor(Qt::red) };
graph->activeTheme()->setBaseColors(color);
graph->activeTheme()->setSingleHighlightColor(Qt::yellow);
					

成员类型文档编制

enum class Q3DTheme:: ColorStyle

颜色样式。

常量 描述
Q3DTheme::ColorStyle::Uniform 0 Objects are rendered in a single color. The color used is specified in baseColors , singleHighlightColor and multiHighlightColor 特性。
Q3DTheme::ColorStyle::ObjectGradient 1 Objects are colored using a full gradient for each object regardless of object height. The gradient used is specified in baseGradients , singleHighlightGradient and multiHighlightGradient 特性。
Q3DTheme::ColorStyle::RangeGradient 2 Objects 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 baseGradients , singleHighlightGradient and multiHighlightGradient 特性。

enum class Q3DTheme:: Theme

内置主题。

常量 描述
Q3DTheme::Theme::Qt 0 A light theme with green as the base color.
Q3DTheme::Theme::PrimaryColors 1 A light theme with yellow as the base color.
Q3DTheme::Theme::StoneMoss 2 A medium dark theme with yellow as the base color.
Q3DTheme::Theme::ArmyBlue 3 A medium light theme with blue as the base color.
Q3DTheme::Theme::Retro 4 A medium light theme with brown as the base color.
Q3DTheme::Theme::Ebony 5 A dark theme with white as the base color.
Q3DTheme::Theme::Isabelle 6 A dark theme with yellow as the base color.
Q3DTheme::Theme::UserDefined 7 A user-defined theme. For more information, see 默认主题 .

特性文档编制

ambientLightStrength : float

This property holds the ambient light strength for the whole graph.

This value determines how evenly and brightly the colors are shown throughout the graph regardless of the light position.

值必须介于 0.0f and 1.0f .

访问函数:

float ambientLightStrength () const
void setAmbientLightStrength (float strength )

通知程序信号:

void ambientLightStrengthChanged (float strength )

backgroundColor : QColor

此特性保持图形背景的颜色。

访问函数:

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

通知程序信号:

void backgroundColorChanged (const QColor & color )

backgroundEnabled : bool

此特性保持背景是否可见。

The background is drawn by using the value of backgroundColor .

访问函数:

bool isBackgroundEnabled () const
void setBackgroundEnabled (bool enabled )

通知程序信号:

void backgroundEnabledChanged (bool enabled )

[read-only] baseColors : const QQmlListProperty < QQuickGraphsColor >

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.

[read-only] baseGradients : const QQmlListProperty < QObject >

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.

colorStyle : Q3DTheme::ColorStyle

此特性保持图形颜色的样式。

One of the ColorStyle 枚举值。

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

访问函数:

Q3DTheme::ColorStyle colorStyle () const
void setColorStyle (Q3DTheme::ColorStyle style )

通知程序信号:

void colorStyleChanged (Q3DTheme::ColorStyle style )

font : QFont

此特性保持用于标签的字体。

访问函数:

QFont font () const
void setFont (const QFont & font )

通知程序信号:

void fontChanged (const QFont & font )

gridEnabled : bool

此特性保持是否绘制栅格线。

此值影响所有栅格线。

访问函数:

bool isGridEnabled () const
void setGridEnabled (bool enabled )

通知程序信号:

void gridEnabledChanged (bool enabled )

gridLineColor : QColor

此特性保持栅格线的颜色。

访问函数:

QColor gridLineColor () const
void setGridLineColor (const QColor & color )

通知程序信号:

void gridLineColorChanged (const QColor & color )

labelBackgroundColor : QColor

此特性保持标签背景的颜色。

不起作用若 labelBackgroundEnabled is false .

访问函数:

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

通知程序信号:

void labelBackgroundColorChanged (const QColor & color )

labelBackgroundEnabled : 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.

访问函数:

bool isLabelBackgroundEnabled () const
void setLabelBackgroundEnabled (bool enabled )

通知程序信号:

void labelBackgroundEnabledChanged (bool enabled )

labelBorderEnabled : bool

此特性保持是否为拥有背景的标签绘制标签边框。

不起作用若 labelBackgroundEnabled is false .

访问函数:

bool isLabelBorderEnabled () const
void setLabelBorderEnabled (bool enabled )

通知程序信号:

void labelBorderEnabledChanged (bool enabled )

labelTextColor : QColor

此特性保持用于标签的字体颜色。

访问函数:

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

通知程序信号:

void labelTextColorChanged (const QColor & color )

labelsEnabled : bool

This property holds whether labels are drawn at all.

若这为 false , all other label properties have no effect.

访问函数:

bool isLabelsEnabled () const
void setLabelsEnabled (bool enabled )

通知程序信号:

void labelsEnabledChanged (bool enabled )

lightColor : QColor

This property holds the color for the ambient and specular light.

This value affects the light specified in Q3DScene .

访问函数:

QColor lightColor () const
void setLightColor (const QColor & color )

通知程序信号:

void lightColorChanged (const QColor & color )

lightStrength : float

This property holds the specular light strength for the whole graph.

值必须介于 0.0f and 10.0f .

This value affects the light specified in Q3DScene .

访问函数:

float lightStrength () const
void setLightStrength (float strength )

通知程序信号:

void lightStrengthChanged (float strength )

multiHighlightColor : QColor

This property holds the highlight color for selected objects.

Used if selectionMode 拥有 QAbstract3DGraph::SelectionRow or QAbstract3DGraph::SelectionColumn 设置标志。

访问函数:

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

通知程序信号:

void multiHighlightColorChanged (const QColor & color )

multiHighlightGradient : QJSValue

This property holds the highlight gradient for selected objects.

Used if selectionMode 拥有 QAbstract3DGraph::SelectionRow or QAbstract3DGraph::SelectionColumn 设置标志。

访问函数:

void setMultiHighlightGradient (const QLinearGradient & gradient )

通知程序信号:

void multiHighlightGradientChangedQML (QJSValue gradient )

shadowStrength : float

This property holds the shadow strength for the whole graph.

The higher the number, the darker the shadows will be. The value must be between 0.0 and 100.0 .

This value affects the light specified in Q3DScene .

访问函数:

float shadowStrength () const
void setShadowStrength (float strength )

通知程序信号:

void shadowStrengthChanged (float strength )

singleHighlightColor : QColor

This property holds the highlight color for a selected object.

Used if selectionMode 拥有 QAbstract3DGraph::SelectionItem 设置标志。

访问函数:

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

通知程序信号:

void singleHighlightColorChanged (const QColor & color )

singleHighlightGradient : QJSValue

This property holds the highlight gradient for a selected object.

Used if selectionMode 拥有 QAbstract3DGraph::SelectionItem 设置标志。

访问函数:

void setSingleHighlightGradient (const QLinearGradient & gradient )

通知程序信号:

void singleHighlightGradientQMLChanged (QJSValue gradient )

type : Q3DTheme::Theme

此特性保持主题的类型。

The type is automatically set when constructing a theme, but can also be changed later. Changing the theme type 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.

访问函数:

Q3DTheme::Theme type () const
void setType (Q3DTheme::Theme themeType )

通知程序信号:

void typeChanged (Q3DTheme::Theme themeType )

windowColor : QColor

This property holds the color of the application window the graph is drawn into.

访问函数:

QColor windowColor () const
void setWindowColor (const QColor & color )

通知程序信号:

void windowColorChanged (const QColor & color )

成员函数文档编制

[explicit] Q3DTheme:: Q3DTheme ( QObject * parent = nullptr)

构造新主题为类型 UserDefined 。可选 parent 参数可以给出,然后会被传递给 QObject 构造函数。

[explicit] Q3DTheme:: Q3DTheme ( Q3DTheme::Theme themeType , QObject * parent = nullptr)

构造新的主题采用 themeType ,可以是某一内置主题来自 Theme 。可选 parent 参数可以给出,然后会被传递给 QObject 构造函数。

[override virtual noexcept] Q3DTheme:: ~Q3DTheme ()

销毁主题。