Q3DTheme Class
Q3DTheme 类为图形提供了一种可视化风格。更多
头文件: | #include <Q3DTheme> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS DataVisualization) target_link_libraries(mytarget PRIVATE Qt6::DataVisualization) |
qmake: | QT += datavisualization |
自 | QtDataVisualization 1.0 |
在 QML 中: | Theme3D |
继承: | QObject |
公共类型
enum | ColorStyle { ColorStyleUniform, ColorStyleObjectGradient, ColorStyleRangeGradient } |
enum | Theme { ThemeQt, ThemePrimaryColors, ThemeDigia, ThemeStoneMoss, ThemeArmyBlue, …, ThemeUserDefined } |
属性
|
|
公共功能
Q3DTheme(QObject *parent = nullptr) | |
Q3DTheme(Q3DTheme::Theme themeType, QObject *parent = nullptr) | |
virtual | ~Q3DTheme() |
float | ambientLightStrength() const |
QColor | backgroundColor() const |
QList<QColor> | baseColors() const |
QList<QLinearGradient> | baseGradients() const |
Q3DTheme::ColorStyle | colorStyle() const |
QFont | font() const |
QColor | gridLineColor() const |
float | highlightLightStrength() const |
bool | isBackgroundEnabled() const |
bool | isGridEnabled() const |
bool | isLabelBackgroundEnabled() const |
bool | isLabelBorderEnabled() const |
QColor | labelBackgroundColor() const |
QColor | labelTextColor() const |
QColor | lightColor() const |
float | lightStrength() const |
QColor | multiHighlightColor() const |
QLinearGradient | multiHighlightGradient() const |
void | setAmbientLightStrength(float strength) |
void | setBackgroundColor(const QColor &color) |
void | setBackgroundEnabled(bool enabled) |
void | setBaseColors(const QList<QColor> &colors) |
void | setBaseGradients(const QList<QLinearGradient> &gradients) |
void | setColorStyle(Q3DTheme::ColorStyle style) |
void | setFont(const QFont &font) |
void | setGridEnabled(bool enabled) |
void | setGridLineColor(const QColor &color) |
void | setHighlightLightStrength(float strength) |
void | setLabelBackgroundColor(const QColor &color) |
void | setLabelBackgroundEnabled(bool enabled) |
void | setLabelBorderEnabled(bool enabled) |
void | setLabelTextColor(const QColor &color) |
void | setLightColor(const QColor &color) |
void | setLightStrength(float strength) |
void | setMultiHighlightColor(const QColor &color) |
void | setMultiHighlightGradient(const QLinearGradient &gradient) |
void | setSingleHighlightColor(const QColor &color) |
void | setSingleHighlightGradient(const QLinearGradient &gradient) |
void | setType(Q3DTheme::Theme themeType) |
void | setWindowColor(const QColor &color) |
QColor | singleHighlightColor() const |
QLinearGradient | singleHighlightGradient() const |
Q3DTheme::Theme | type() const |
QColor | windowColor() const |
信号
void | ambientLightStrengthChanged(float strength) |
void | backgroundColorChanged(const QColor &color) |
void | backgroundEnabledChanged(bool enabled) |
void | baseColorsChanged(const QList<QColor> &colors) |
void | baseGradientsChanged(const QList<QLinearGradient> &gradients) |
void | colorStyleChanged(Q3DTheme::ColorStyle style) |
void | fontChanged(const QFont &font) |
void | gridEnabledChanged(bool enabled) |
void | gridLineColorChanged(const QColor &color) |
void | highlightLightStrengthChanged(float strength) |
void | labelBackgroundColorChanged(const QColor &color) |
void | labelBackgroundEnabledChanged(bool enabled) |
void | labelBorderEnabledChanged(bool enabled) |
void | labelTextColorChanged(const QColor &color) |
void | lightColorChanged(const QColor &color) |
void | lightStrengthChanged(float strength) |
void | multiHighlightColorChanged(const QColor &color) |
void | multiHighlightGradientChanged(const QLinearGradient &gradient) |
void | singleHighlightColorChanged(const QColor &color) |
void | singleHighlightGradientChanged(const QLinearGradient &gradient) |
void | typeChanged(Q3DTheme::Theme themeType) |
void | windowColorChanged(const QColor &color) |
详细说明
指定影响整个图表的视觉属性。有几种内置主题,可按原样使用或自由修改。
通过使用QAbstract3DSeries 属性,可以在系列中明确设置以下属性:baseColors、baseGradients 和colorStyle 。
可以使用ThemeUserDefined 枚举值从头开始创建主题。使用默认构造函数创建主题会生成一个新的用户自定义主题。
默认主题
下表列出了由主题控制的属性以及ThemeUserDefined 的默认值。
使用示例
创建一个不做任何修改的内置主题:
创建内置主题并修改部分属性:
Q3DTheme *theme = new Q3DTheme(Q3DTheme::ThemeQt); theme->setBackgroundEnabled(false); theme->setLabelBackgroundEnabled(false);
创建用户自定义主题
Q3DTheme *theme = new Q3DTheme(); theme->setAmbientLightStrength(0.3f); theme->setBackgroundColor(QColor(QRgb(0x99ca53))); theme->setBackgroundEnabled(true); theme->setBaseColor(QColor(QRgb(0x209fdf))); theme->setColorStyle(Q3DTheme::ColorStyleUniform); theme->setFont(QFont(QStringLiteral("Impact"), 35)); theme->setGridEnabled(true); theme->setGridLineColor(QColor(QRgb(0x99ca53))); theme->setHighlightLightStrength(7.0f); 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)));
创建内置主题并在设置后修改部分属性:
成员类型文档
enum Q3DTheme::ColorStyle
颜色样式。
常数 | 值 | 说明 |
---|---|---|
Q3DTheme::ColorStyleUniform | 0 | 对象以单一颜色渲染。使用的颜色在baseColors 、singleHighlightColor 和multiHighlightColor 属性中指定。 |
Q3DTheme::ColorStyleObjectGradient | 1 | 无论对象高度如何,每个对象都使用全渐变色渲染。使用的渐变色在baseGradients,singleHighlightGradient 和multiHighlightGradient 属性中指定。 |
Q3DTheme::ColorStyleRangeGradient | 2 | 根据对象的高度及其在 Y 轴上的位置,使用全梯度的一部分为对象着色。使用的梯度在baseGradients,singleHighlightGradient 和multiHighlightGradient 属性中指定。 |
enum Q3DTheme::Theme
内置主题
常数 | 值 | 描述 |
---|---|---|
Q3DTheme::ThemeQt | 0 | 以绿色为基色的浅色主题。 |
Q3DTheme::ThemePrimaryColors | 1 | 以黄色为基色的浅色主题。 |
Q3DTheme::ThemeDigia | 2 | 以灰色为基色的浅色主题。 |
Q3DTheme::ThemeStoneMoss | 3 | 以黄色为基色的中度深色主题。 |
Q3DTheme::ThemeArmyBlue | 4 | 以蓝色为基色的中浅色主题。 |
Q3DTheme::ThemeRetro | 5 | 以棕色为基色的中浅色主题。 |
Q3DTheme::ThemeEbony | 6 | 以白色为基色的深色主题。 |
Q3DTheme::ThemeIsabelle | 7 | 以黄色为基色的深色主题。 |
Q3DTheme::ThemeUserDefined | 8 | 用户自定义主题。更多信息,请参阅Default Theme 。 |
属性文档
ambientLightStrength : float
该属性用于保存整个图形的环境光强度。
无论光线位置如何,该值都将决定整个图表中颜色显示的均匀度和亮度。
该值必须介于0.0f
和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
该属性表示背景是否可见。
使用backgroundColor 的值绘制背景。
访问功能:
bool | isBackgroundEnabled() const |
void | setBackgroundEnabled(bool enabled) |
Notifier 信号:
void | backgroundEnabledChanged(bool enabled) |
baseColors : QList<QColor>
该属性包含用于图形中所有对象的基本颜色列表,按系列逐一显示。
如果系列数多于颜色数,颜色列表将重新打包,并从列表中的第一种颜色开始。
如果colorStyle 不是ColorStyleUniform ,则不会立即生效。
可以通过在系列中明确设置baseColor 来覆盖此值。
访问功能:
QList<QColor> | baseColors() const |
void | setBaseColors(const QList<QColor> &colors) |
通知信号:
void | baseColorsChanged(const QList<QColor> &colors) |
baseGradients : QList<QLinearGradient>
该属性包含用于图形中所有对象的基本渐变效果列表,按序列逐一显示。
如果系列的数量多于渐变效果,渐变效果列表将重新打包,并从列表中的第一个渐变效果开始。
如果colorStyle 为ColorStyleUniform ,则不会立即生效。
可以通过在系列中明确设置baseGradient 来覆盖该值。
访问功能:
QList<QLinearGradient> | baseGradients() const |
void | setBaseGradients(const QList<QLinearGradient> &gradients) |
通知信号:
void | baseGradientsChanged(const QList<QLinearGradient> &gradients) |
colorStyle : ColorStyle
该属性用于保存图形颜色的样式。
ColorStyle 枚举值之一。
可以通过在系列中明确设置colorStyle 来重写该值。
访问功能:
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) |
highlightLightStrength : float
该属性用于保存所选对象的镜面反射光强度。
该值必须介于0.0f
和10.0f
之间。
访问功能:
float | highlightLightStrength() const |
void | setHighlightLightStrength(float strength) |
通知信号:
void | highlightLightStrengthChanged(float strength) |
labelBackgroundColor : QColor
该属性保存标签背景的颜色。
如果labelBackgroundEnabled 为false
则不起作用。
访问功能:
QColor | labelBackgroundColor() const |
void | setLabelBackgroundColor(const QColor &color) |
Notifier 信号:
void | labelBackgroundColorChanged(const QColor &color) |
labelBackgroundEnabled : bool
该属性表示标签是以彩色背景还是全透明背景绘制。
labelBackgroundColor 值(包括 alpha)用于绘制背景。
有背景的标签按最长标签绘制,每个轴的尺寸相等,文本居中。无背景的标签按原样绘制,并根据其在图表中的位置向左或向右对齐。
访问功能:
bool | isLabelBackgroundEnabled() const |
void | setLabelBackgroundEnabled(bool enabled) |
通知信号
void | labelBackgroundEnabledChanged(bool enabled) |
labelBorderEnabled : bool
此属性决定是否为有背景的标签绘制标签边框。
如果labelBackgroundEnabled 为false
则无影响。
访问功能:
bool | isLabelBorderEnabled() const |
void | setLabelBorderEnabled(bool enabled) |
Notifier 信号:
void | labelBorderEnabledChanged(bool enabled) |
labelTextColor : QColor
该属性用于保存标签所用字体的颜色。
访问功能:
QColor | labelTextColor() const |
void | setLabelTextColor(const QColor &color) |
通知信号:
void | labelTextColorChanged(const QColor &color) |
lightColor : QColor
该属性用于保存环境光和镜面反射光的颜色。
该值会影响Q3DScene 中指定的光线。
访问功能:
QColor | lightColor() const |
void | setLightColor(const QColor &color) |
Notifier 信号:
void | lightColorChanged(const QColor &color) |
lightStrength : float
该属性用于保存整个图形的镜面反射光强度。
该值必须介于0.0f
和10.0f
之间。
该值会影响Q3DScene 中指定的光线。
访问功能:
float | lightStrength() const |
void | setLightStrength(float strength) |
通知信号:
void | lightStrengthChanged(float strength) |
multiHighlightColor : QColor
该属性用于保存选定对象的高亮颜色。
在selectionMode 设置了QAbstract3DGraph::SelectionRow
或QAbstract3DGraph::SelectionColumn
标志时使用。
访问功能:
QColor | multiHighlightColor() const |
void | setMultiHighlightColor(const QColor &color) |
通知信号:
void | multiHighlightColorChanged(const QColor &color) |
multiHighlightGradient : QLinearGradient
该属性用于保存所选对象的高光渐变。
在selectionMode 设置了QAbstract3DGraph::SelectionRow
或QAbstract3DGraph::SelectionColumn
标志时使用。
访问功能:
QLinearGradient | multiHighlightGradient() const |
void | setMultiHighlightGradient(const QLinearGradient &gradient) |
通知信号:
void | multiHighlightGradientChanged(const QLinearGradient &gradient) |
singleHighlightColor : QColor
该属性用于保存选定对象的高亮颜色。
在selectionMode 设置了QAbstract3DGraph::SelectionItem
标志时使用。
访问功能:
QColor | singleHighlightColor() const |
void | setSingleHighlightColor(const QColor &color) |
通知信号:
void | singleHighlightColorChanged(const QColor &color) |
singleHighlightGradient : QLinearGradient
该属性用于保存选定对象的高光渐变。
在selectionMode 设置了QAbstract3DGraph::SelectionItem
标志时使用。
访问功能:
QLinearGradient | singleHighlightGradient() const |
void | setSingleHighlightGradient(const QLinearGradient &gradient) |
通知信号:
void | singleHighlightGradientChanged(const QLinearGradient &gradient) |
type : Theme
该属性用于保存主题的类型。
该类型会在构建主题时自动设置,但也可以稍后更改。更改主题类型会将主题的所有其他属性更改为预定义主题指定的属性。更改图表活动主题的主题类型还将重置所有附加序列,使其使用新主题。
访问功能:
Q3DTheme::Theme | type() const |
void | setType(Q3DTheme::Theme themeType) |
通知信号:
void | typeChanged(Q3DTheme::Theme themeType) |
windowColor : QColor
该属性用于保存绘制图形时应用窗口的颜色。
访问功能:
QColor | windowColor() const |
void | setWindowColor(const QColor &color) |
Notifier 信号:
void | windowColorChanged(const QColor &color) |
成员函数 文档
[explicit]
Q3DTheme::Q3DTheme(QObject *parent = nullptr)
构造ThemeUserDefined 类型的新主题。可以给出一个可选的parent 参数,然后将其传递给QObject 构造函数。
[explicit]
Q3DTheme::Q3DTheme(Q3DTheme::Theme themeType, QObject *parent = nullptr)
使用themeType 构建一个新主题,该主题可以是Theme 中的一个内置主题。可选的parent 参数会传递给QObject 构造函数。
[virtual noexcept]
Q3DTheme::~Q3DTheme()
破坏主题。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.