PySide6.QtGraphs.QGraphsTheme

class QGraphsTheme

QGraphsTheme 类为图表提供了视觉样式。更多

PySide6.QtGraphs.QGraphsTheme 的继承图

在版本6.8中添加。

概要

属性

方法

插槽

信号

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

警告

本节包含从C++自动翻译到Python的代码片段,可能包含错误。

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

可以使用UserDefined枚举值从头开始创建主题。使用默认构造函数创建主题会生成一个新的用户定义主题。

自定义主题

默认主题是QtGreen,但可以自定义每个属性。

下表列出了由主题控制的属性以及UserDefined的默认值。

属性

默认值

backgroundVisible

true

seriesColors

Qt::black

seriesGradients

QLinearGradient。基本上是全黑的。

colorStyle

统一

labelFont

QFont

gridVisible

true

labelBackgroundVisible

true

labelBorderVisible

true

labelsVisible

true

使用示例

创建一个没有任何修改的内置主题:

theme = QGraphsTheme()

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

theme = QGraphsTheme()
theme.setBackgroundVisible(False)
theme.setLabelBackgroundVisible(False)

修改用户定义的主题。主题的创建方式与之前的代码片段相同:

theme.setTheme(QGraphsTheme.Theme.UserDefined)
theme.setBackgroundColor(QColor(QRgb(0x99ca53)))
theme.setBackgroundVisible(True)
colors = { QColor(QRgb(0x209fdf)) }
theme.setSeriesColors(colors)
theme.setColorStyle(QGraphsTheme.ColorStyle.Uniform)
theme.setLabelFont(QFont("Impact", 35))
theme.setGridVisible(True)
gridline = theme.grid()
gridline.setMainColor(QColor(QRgb(0x99ca53)))
theme.setGrid(gridline)
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.setBackgroundColor(QColor(QRgb(0xffffff)))

在主题已设置为图表后修改一些属性:

quickWidget = QQuickWidget()
bars = Q3DBarsWidgetItem()
bars.setWidget(quickWidget)
bars.widget().setMinimumSize(QSize(512, 512))
bars.activeTheme().setTheme(QGraphsTheme.Theme.MixSeries)
color = { QColor(Qt.red) }
bars.activeTheme().setSeriesColors(color)
bars.activeTheme().setSingleHighlightColor(Qt.yellow)
class Theme

内置主题。

常量

描述

QGraphsTheme.Theme.QtGreen

以绿色为基色的浅色主题。

QGraphsTheme.Theme.QtGreenNeon

以绿色霓虹灯为基色的浅色主题。

QGraphsTheme.Theme.MixSeries

一个包含多种颜色的混合主题。

QGraphsTheme.Theme.OrangeSeries

以橙色为基色的主题。

QGraphsTheme.Theme.YellowSeries

以黄色为基色的主题。

QGraphsTheme.Theme.BlueSeries

以蓝色为基色的主题。

QGraphsTheme.Theme.PurpleSeries

以紫色为基色的主题。

QGraphsTheme.Theme.GreySeries

以灰色为基色的主题。

QGraphsTheme.Theme.UserDefined

用户自定义主题。更多信息,请参见 自定义 主题

class ColorStyle

渐变类型。

常量

描述

QGraphsTheme.ColorStyle.Uniform

对象以单一颜色渲染。使用的颜色在seriesColorssingleHighlightColormultiHighlightColor属性中指定。

QGraphsTheme.ColorStyle.ObjectGradient

对象使用每个对象的完整渐变进行着色,无论对象高度如何。使用的渐变在seriesGradientssingleHighlightGradientmultiHighlightGradient属性中指定。

QGraphsTheme.ColorStyle.RangeGradient

对象根据其高度和Y轴上的位置使用完整渐变色的一部分进行着色。使用的渐变色在seriesGradientssingleHighlightGradientmultiHighlightGradient属性中指定。

class ForceTheme
class ColorScheme

表示图表的配色方案。

常量

描述

QGraphsTheme.ColorScheme.Automatic

如果可用,背景颜色遵循平台的颜色方案。如果不可用,则使用浅色外观。

QGraphsTheme.ColorScheme.Light

背景颜色比文本颜色浅,即主题是浅色的。

QGraphsTheme.ColorScheme.Dark

背景颜色比文本颜色更深,即主题是暗色的。

另请参阅

ColorScheme

class GradientQMLStyle

注意

当使用from __feature__ import true_property时,属性可以直接使用,否则通过访问器函数使用。

property axisXᅟ: QGraphsLine
Access functions:
property axisXLabelFontᅟ: QFont

此属性保存用于x轴标签的字体。

Access functions:
property axisYᅟ: QGraphsLine
Access functions:
property axisYLabelFontᅟ: QFont

此属性保存用于y轴标签的字体。

Access functions:
property axisZᅟ: QGraphsLine
Access functions:
property axisZLabelFontᅟ: QFont

此属性保存用于z轴标签的字体。

Access functions:
property backgroundColorᅟ: QColor

此属性保存图形绘制到的视图的颜色。默认值取决于colorScheme

Access functions:
property backgroundVisibleᅟ: bool

此属性表示背景是否可见。

背景是通过使用backgroundColor的值来绘制的。默认值为true

Access functions:
property borderColorsᅟ: list of QColor

此属性保存用于图表中所有对象的边框颜色列表,按系列排列。

如果系列数量多于颜色数量,颜色列表会循环并从列表中的第一个颜色重新开始。

如果colorStyle不是Uniform,则不会立即生效。

Access functions:
property borderWidthᅟ: float

此属性保存图形中边框的宽度(如果有)。默认值为1.0

Access functions:
property colorSchemeᅟ: QGraphsTheme.ColorScheme

图表使用的配色方案。

另请参阅

ColorScheme

Access functions:
property colorStyleᅟ: QGraphsTheme.ColorStyle

图表颜色的样式。ColorStyle 枚举值之一。

这个值可以通过在系列中显式设置Abstract3DSeries.colorStyle来覆盖。

注意

此属性在Qt Graphs的2D中无效。

另请参阅

ColorStyle

Access functions:
property gridᅟ: QGraphsLine
Access functions:
property gridVisibleᅟ: bool

此属性表示是否绘制网格线。

此值影响所有网格线。默认值为true

Access functions:
property labelBackgroundColorᅟ: QColor

此属性保存标签背景的颜色。

如果labelBackgroundVisiblefalse,则无效。默认值取决于colorScheme

Access functions:
property labelBackgroundVisibleᅟ: bool

此属性决定标签是否以彩色背景或完全透明背景绘制。

labelBackgroundColor 值(包括 alpha)用于绘制背景。

带有背景的标签会根据最长的标签在每个轴上绘制为相同大小,并且文本在其中居中。没有背景的标签则按原样绘制,并根据它们在图表中的位置左对齐或右对齐。默认值为true

Access functions:
property labelBorderVisibleᅟ: bool

此属性保存是否绘制具有背景的标签的标签边框。

如果labelBackgroundVisiblefalse,则无效。默认值为true

Access functions:
property labelFontᅟ: QFont

此属性保存用于标签的字体。

Access functions:
property labelTextColorᅟ: QColor

此属性保存用于标签的字体颜色。默认值取决于colorScheme

Access functions:
property labelsVisibleᅟ: bool

此属性保存是否绘制标签。

如果这是false,所有其他标签属性将无效。默认值为true

Access functions:
property multiHighlightColorᅟ: QColor

此属性保存所选对象的高亮颜色。

如果selectionMode设置了QtGraphs3D::SelectionFlag::RowQtGraphs3D::SelectionFlag::Column标志,则使用此选项。默认值取决于colorScheme

Access functions:
property plotAreaBackgroundColorᅟ: QColor

此属性保存图表绘图区域背景的颜色。默认值取决于colorScheme

Access functions:
property plotAreaBackgroundVisibleᅟ: bool

此属性表示绘图区域背景是否可见。

背景是通过使用plotAreaBackgroundColor的值来绘制的。默认值为true

Access functions:
property seriesColorsᅟ: list of QColor

此属性保存用于图表中所有对象的基础颜色列表,按系列逐个系列。

如果系列数量多于颜色数量,颜色列表会循环并从列表中的第一个颜色重新开始。

如果colorStyle不是Uniform,则不会立即生效。

这个值可以通过在系列中显式设置baseColor来覆盖。

Access functions:
property singleHighlightColorᅟ: QColor

此属性保存所选对象的高亮颜色。

如果selectionMode设置了QtGraphs3D::SelectionFlag::Item标志,则使用此选项。默认值取决于colorScheme

Access functions:
property themeᅟ: QGraphsTheme.Theme

主题的类型。如果未设置类型,则类型为QtGreen。在项目构建后更改主题类型将更改主题的所有其他属性为预定义主题指定的属性。更改图表的活动主题类型还将重置所有附加的系列以使用新主题。

Access functions:
__init__([parent=None])
Parameters:

父对象QObject

axisX()
Return type:

QGraphsLine

另请参阅

setAxisX()

属性 axisXᅟ 的获取器。

axisXChanged()

属性 axisXᅟ 的通知信号。

axisXLabelFont()
Return type:

QFont

另请参阅

setAxisXLabelFont()

属性 axisXLabelFontᅟ 的获取器。

axisXLabelFontChanged()

属性 axisXLabelFontᅟ 的通知信号。

axisY()
Return type:

QGraphsLine

另请参阅

setAxisY()

属性 axisYᅟ 的获取器。

axisYChanged()

属性 axisYᅟ 的通知信号。

axisYLabelFont()
Return type:

QFont

另请参阅

setAxisYLabelFont()

属性 axisYLabelFontᅟ 的获取器。

axisYLabelFontChanged()

属性 axisYLabelFontᅟ 的通知信号。

axisZ()
Return type:

QGraphsLine

另请参阅

setAxisZ()

属性 axisZᅟ 的获取器。

axisZChanged()

属性 axisZᅟ 的通知信号。

axisZLabelFont()
Return type:

QFont

另请参阅

setAxisZLabelFont()

属性 axisZLabelFontᅟ 的获取器。

axisZLabelFontChanged()

属性 axisZLabelFontᅟ 的通知信号。

backgroundColor()
Return type:

QColor

另请参阅

setBackgroundColor()

获取属性 backgroundColorᅟ 的Getter。

backgroundColorChanged()

属性 backgroundColorᅟ 的通知信号。

backgroundVisibleChanged()

属性 backgroundVisibleᅟ 的通知信号。

borderColors()
Return type:

QColor的列表

另请参阅

setBorderColors()

属性 borderColorsᅟ 的获取器。

borderColorsChanged()

属性 borderColorsᅟ 的通知信号。

borderWidth()
Return type:

浮点数

另请参阅

setBorderWidth()

属性 borderWidthᅟ 的获取器。

borderWidthChanged()

属性 borderWidthᅟ 的通知信号。

colorScheme()
Return type:

ColorScheme

另请参阅

setColorScheme()

属性 colorSchemeᅟ 的获取器。

colorSchemeChanged()

属性 colorSchemeᅟ 的通知信号。

colorStyle()
Return type:

ColorStyle

另请参阅

setColorStyle()

属性 colorStyleᅟ 的获取器。

colorStyleChanged(type)
Parameters:

类型ColorStyle

属性 colorStyleᅟ 的通知信号。

dirtyBits()
Return type:

QGraphsThemeDirtyBitField

grid()
Return type:

QGraphsLine

另请参阅

setGrid()

属性 gridᅟ 的获取器。

gridChanged()

属性 gridᅟ 的通知信号。

gridVisibleChanged()

属性 gridVisibleᅟ 的通知信号。

handleBaseColorUpdate()
handleBaseGradientUpdate()
isBackgroundVisible()
Return type:

布尔

属性 backgroundVisibleᅟ 的获取器。

isGridVisible()
Return type:

布尔

属性 gridVisibleᅟ 的获取器。

isLabelBackgroundVisible()
Return type:

布尔

属性 labelBackgroundVisibleᅟ 的获取器。

isLabelBorderVisible()
Return type:

布尔

属性 labelBorderVisibleᅟ 的获取器。

isPlotAreaBackgroundVisible()
Return type:

布尔

属性 plotAreaBackgroundVisibleᅟ 的获取器。

labelBackgroundColor()
Return type:

QColor

属性 labelBackgroundColorᅟ 的获取器。

labelBackgroundColorChanged()

属性 labelBackgroundColorᅟ 的通知信号。

labelBackgroundVisibleChanged()

属性 labelBackgroundVisibleᅟ 的通知信号。

labelBorderVisibleChanged()

属性 labelBorderVisibleᅟ 的通知信号。

labelFont()
Return type:

QFont

另请参阅

setLabelFont()

属性 labelFontᅟ 的获取器。

labelFontChanged()

属性 labelFontᅟ 的通知信号。

labelTextColor()
Return type:

QColor

另请参阅

setLabelTextColor()

属性 labelTextColorᅟ 的获取器。

labelTextColorChanged()

属性 labelTextColorᅟ 的通知信号。

labelsVisible()
Return type:

布尔

另请参阅

setLabelsVisible()

属性 labelsVisibleᅟ 的获取器。

labelsVisibleChanged()

属性 labelsVisibleᅟ 的通知信号。

multiHighlightColor()
Return type:

QColor

属性 multiHighlightColorᅟ 的获取器。

multiHighlightColorChanged(color)
Parameters:

颜色QColor

属性 multiHighlightColorᅟ 的通知信号。

multiHighlightGradient()
Return type:

QLinearGradient

multiHighlightGradientChanged(gradient)
Parameters:

渐变QLinearGradient

multiHighlightGradientQMLChanged()
plotAreaBackgroundColor()
Return type:

QColor

属性 plotAreaBackgroundColorᅟ 的获取器。

plotAreaBackgroundColorChanged()

属性 plotAreaBackgroundColorᅟ 的通知信号。

plotAreaBackgroundVisibleChanged()

属性 plotAreaBackgroundVisibleᅟ 的通知信号。

resetColorTheme()
resetDirtyBits()
resetThemeDirty()
seriesColors()
Return type:

QColor的列表

另请参阅

setSeriesColors()

属性 seriesColorsᅟ 的获取器。

seriesColorsChanged(list)
Parameters:

list – QColor的列表

属性 seriesColorsᅟ 的通知信号。

seriesGradients()
Return type:

QLinearGradient的列表

返回主题使用的系列渐变列表。

另请参阅

setSeriesGradients()

seriesGradientsChanged(list)
Parameters:

list – QLinearGradient 的列表

setAxisX(newAxisX)
Parameters:

newAxisXQGraphsLine

另请参阅

axisX()

属性 axisXᅟ 的设置器。

setAxisXLabelFont(newAxisXLabelFont)
Parameters:

newAxisXLabelFontQFont

另请参阅

axisXLabelFont()

属性 axisXLabelFontᅟ 的设置器。

setAxisY(newAxisY)
Parameters:

newAxisYQGraphsLine

另请参阅

axisY()

属性 axisYᅟ 的设置器。

setAxisYLabelFont(newAxisYLabelFont)
Parameters:

newAxisYLabelFontQFont

另请参阅

axisYLabelFont()

属性 axisYLabelFontᅟ 的设置器。

setAxisZ(newAxisZ)
Parameters:

newAxisZQGraphsLine

另请参阅

axisZ()

属性 axisZᅟ 的设置器。

setAxisZLabelFont(newAxisZLabelFont)
Parameters:

newAxisZLabelFontQFont

另请参阅

axisZLabelFont()

属性 axisZLabelFontᅟ 的设置器。

setBackgroundColor(newBackgroundColor)
Parameters:

newBackgroundColorQColor

另请参阅

backgroundColor()

属性 backgroundColorᅟ 的设置器。

setBackgroundVisible(newBackgroundVisible)
Parameters:

newBackgroundVisible – 布尔值

另请参阅

isBackgroundVisible()

属性 backgroundVisibleᅟ 的设置器。

setBorderColors(newBorderColors)
Parameters:

newBorderColors – QColor 的列表

另请参阅

borderColors()

属性 borderColorsᅟ 的设置器。

setBorderWidth(newBorderWidth)
Parameters:

newBorderWidth – 浮点数

另请参阅

borderWidth()

属性 borderWidthᅟ 的设置器。

setColorScheme(newColorScheme)
Parameters:

newColorSchemeColorScheme

另请参阅

colorScheme()

属性 colorSchemeᅟ 的设置器。

setColorStyle(newColorStyle)
Parameters:

newColorStyleColorStyle

另请参阅

colorStyle()

属性 colorStyleᅟ 的设置器。

setGrid(newGrid)
Parameters:

newGridQGraphsLine

另请参阅

grid()

属性 gridᅟ 的设置器。

setGridVisible(newGridVisibility)
Parameters:

newGridVisibility – 布尔值

另请参阅

isGridVisible()

属性 gridVisibleᅟ 的设置器。

setLabelBackgroundColor(newLabelBackgroundColor)
Parameters:

newLabelBackgroundColorQColor

另请参阅

labelBackgroundColor()

属性 labelBackgroundColorᅟ 的设置器。

setLabelBackgroundVisible(newLabelBackgroundVisibility)
Parameters:

newLabelBackgroundVisibility – 布尔值

属性 labelBackgroundVisibleᅟ 的设置器。

setLabelBorderVisible(newLabelBorderVisibility)
Parameters:

newLabelBorderVisibility – 布尔值

另请参阅

isLabelBorderVisible()

属性 labelBorderVisibleᅟ 的设置器。

setLabelFont(newFont)
Parameters:

newFontQFont

另请参阅

labelFont()

属性 labelFontᅟ 的设置器。

setLabelTextColor(newLabelTextColor)
Parameters:

newLabelTextColorQColor

另请参阅

labelTextColor()

属性 labelTextColorᅟ 的设置器。

setLabelsVisible(newLabelsVisibility)
Parameters:

newLabelsVisibility – 布尔值

另请参阅

labelsVisible()

属性 labelsVisibleᅟ 的设置器。

setMultiHighlightColor(newMultiHighlightColor)
Parameters:

newMultiHighlightColorQColor

另请参阅

multiHighlightColor()

属性 multiHighlightColorᅟ 的设置器。

setMultiHighlightGradient(gradient)
Parameters:

渐变QLinearGradient

setPlotAreaBackgroundColor(newBackgroundColor)
Parameters:

newBackgroundColorQColor

属性 plotAreaBackgroundColorᅟ 的设置器。

setPlotAreaBackgroundVisible(newBackgroundVisibility)
Parameters:

newBackgroundVisibility – 布尔值

属性 plotAreaBackgroundVisibleᅟ 的设置器。

setSeriesColors(newSeriesColors)
Parameters:

newSeriesColors – QColor 的列表

另请参阅

seriesColors()

属性 seriesColorsᅟ 的设置器。

setSeriesGradients(newSeriesGradients)
Parameters:

newSeriesGradients – QLinearGradient 的列表

newSeriesGradients设置为主题的系列渐变。

另请参阅

seriesGradients()

setSingleHighlightColor(newSingleHighlightColor)
Parameters:

newSingleHighlightColorQColor

另请参阅

singleHighlightColor()

属性 singleHighlightColorᅟ 的设置器。

setSingleHighlightGradient(gradient)
Parameters:

渐变QLinearGradient

setTheme(newTheme[, force=QGraphsTheme.ForceTheme.No])
Parameters:

另请参阅

theme()

singleHighlightColor()
Return type:

QColor

属性 singleHighlightColorᅟ 的获取器。

singleHighlightColorChanged(color)
Parameters:

颜色QColor

属性 singleHighlightColorᅟ 的通知信号。

singleHighlightGradient()
Return type:

QLinearGradient

singleHighlightGradientChanged(gradient)
Parameters:

渐变QLinearGradient

singleHighlightGradientQMLChanged()
theme()
Return type:

主题

另请参阅

setTheme()

属性 themeᅟ 的获取器。

themeChanged(theme)
Parameters:

主题主题

属性 themeᅟ 的通知信号。

themeDirty()
Return type:

布尔

update()