QGraphsTheme class provides a visual style for graphs. 更多...
| 頭: |
#include <QGraphsTheme>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
|
| qmake: |
QT += graphs
|
| 在 QML: | GraphsTheme |
| 繼承: | QObject and QQmlParserStatus |
| 枚舉類 | ColorScheme { Automatic, Light, Dark } |
| 枚舉類 | ColorStyle { Uniform, ObjectGradient, RangeGradient } |
| 枚舉類 | Theme { QtGreen, QtGreenNeon, MixSeries, OrangeSeries, YellowSeries, …, UserDefined } |
|
|
| QGraphsLine | axisX () const |
| QFont | axisXLabelFont () const |
| QGraphsLine | axisY () const |
| QFont | axisYLabelFont () const |
| QGraphsLine | axisZ () const |
| QFont | axisZLabelFont () const |
| QColor | backgroundColor () const |
| QList<QColor> | borderColors () const |
| qreal | borderWidth () const |
| QGraphsTheme::ColorScheme | colorScheme () const |
| QGraphsTheme::ColorStyle | colorStyle () const |
| QGraphsLine | grid () 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 | setAxisX (const QGraphsLine & newAxisX ) |
| void | setAxisXLabelFont (const QFont & newAxisXLabelFont ) |
| void | setAxisY (const QGraphsLine & newAxisY ) |
| void | setAxisYLabelFont (const QFont & newAxisYLabelFont ) |
| void | setAxisZ (const QGraphsLine & newAxisZ ) |
| void | setAxisZLabelFont (const QFont & newAxisZLabelFont ) |
| void | setBackgroundColor (QColor newBackgroundColor ) |
| void | setBackgroundVisible (bool newBackgroundVisible ) |
| void | setBorderColors (const QList<QColor> & newBorderColors ) |
| void | setBorderWidth (qreal newBorderWidth ) |
| void | setColorScheme (QGraphsTheme::ColorScheme newColorScheme ) |
| void | setColorStyle (QGraphsTheme::ColorStyle newColorStyle ) |
| void | setGrid (const QGraphsLine & newGrid ) |
| void | setGridVisible (bool newGridVisibility ) |
| void | setLabelBackgroundColor (QColor newLabelBackgroundColor ) |
| void | setLabelBackgroundVisible (bool newLabelBackgroundVisibility ) |
| void | setLabelBorderVisible (bool newLabelBorderVisibility ) |
| void | setLabelFont (const QFont & newFont ) |
| void | setLabelTextColor (QColor newLabelTextColor ) |
| void | setLabelsVisible (bool newLabelsVisibility ) |
| void | setMultiHighlightColor (QColor newMultiHighlightColor ) |
| void | setPlotAreaBackgroundColor (QColor newBackgroundColor ) |
| void | setPlotAreaBackgroundVisible (bool newBackgroundVisibility ) |
| void | setSeriesColors (const QList<QColor> & newSeriesColors ) |
| void | setSeriesGradients (const QList<QLinearGradient> & newSeriesGradients ) |
| void | setSingleHighlightColor (QColor newSingleHighlightColor ) |
| void | setTheme (QGraphsTheme::Theme newTheme , QGraphsTheme::ForceTheme force = ForceTheme::No) |
| QColor | singleHighlightColor () const |
| QGraphsTheme::Theme | theme () const |
| void | axisXChanged () |
| void | axisXLabelFontChanged () |
| void | axisYChanged () |
| void | axisYLabelFontChanged () |
| void | axisZChanged () |
| void | axisZLabelFontChanged () |
| void | backgroundColorChanged () |
| void | backgroundVisibleChanged () |
| void | borderColorsChanged () |
| void | borderWidthChanged () |
| void | colorSchemeChanged () |
| void | colorStyleChanged (QGraphsTheme::ColorStyle type ) |
| void | gridChanged () |
| void | gridVisibleChanged () |
| void | labelBackgroundColorChanged () |
| void | labelBackgroundVisibleChanged () |
| void | labelBorderVisibleChanged () |
| void | labelFontChanged () |
| void | labelTextColorChanged () |
| void | labelsVisibleChanged () |
| void | multiHighlightColorChanged (QColor color ) |
| void | multiHighlightGradientQMLChanged () |
| void | plotAreaBackgroundColorChanged () |
| void | plotAreaBackgroundVisibleChanged () |
| void | seriesColorsChanged (const QList<QColor> & list ) |
| void | singleHighlightColorChanged (QColor color ) |
| void | singleHighlightGradientQMLChanged () |
| void | themeChanged (QGraphsTheme::Theme theme ) |
指定影響整個圖形的視覺特性。有幾個內置主題可以使用或自由修改。
可以從新創建主題使用 UserDefined 枚舉值。使用默認構造函數創建主題會産生新的用戶定義主題。
The default theme is QtGreen , but it is possible to customize each property.
The following table lists the properties controlled by a theme and the default values for UserDefined .
| 特性 | 默認值 |
|---|---|
| backgroundVisible |
true
|
| seriesColors | Qt::black |
| seriesGradients | QLinearGradient 。本質上全黑。 |
| colorStyle | Uniform |
| labelFont | QFont |
| gridVisible |
true
|
| labelBackgroundVisible |
true
|
| labelBorderVisible |
true
|
| labelsVisible |
true
|
創建內置主題不做任何修改:
QGraphsTheme *theme = new QGraphsTheme();
創建內置主題並修改一些特性:
QGraphsTheme *theme = new QGraphsTheme(); theme->setBackgroundVisible(false); theme->setLabelBackgroundVisible(false);
Modifying a user-defined theme. The theme has been created the same way it was in the previous snippets:
theme->setTheme(QGraphsTheme::Theme::UserDefined); 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); auto 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)));
Modifying some properties after theme has been set to a graph:
QQuickWidget quickWidget; Q3DBarsWidgetItem bars; bars.setWidget(&quickWidget); bars.widget()->setMinimumSize(QSize(512, 512)); bars.activeTheme()->setTheme(QGraphsTheme::Theme::MixSeries); QList<QColor> color = { QColor(Qt::red) }; bars.activeTheme()->setSeriesColors(color); bars.activeTheme()->setSingleHighlightColor(Qt::yellow);
Represents the color scheme of the graph.
| 常量 | 值 | 描述 |
|---|---|---|
QGraphsTheme::ColorScheme::Automatic
|
0
|
The background colors follow the platform color scheme if available. If unavailable, the Light appearance is used. |
QGraphsTheme::ColorScheme::Light
|
1
|
背景色比文本顔色更淺 (即:主題為淺色)。 |
QGraphsTheme::ColorScheme::Dark
|
2
|
背景色比文本顔色更暗,(即:主題為深色)。 |
另請參閱 Qt::ColorScheme .
Gradient types.
| 常量 | 值 | 描述 |
|---|---|---|
QGraphsTheme::ColorStyle::Uniform
|
0
|
Objects are rendered in a single color. The color used is specified in seriesColors , singleHighlightColor and multiHighlightColor 特性。 |
QGraphsTheme::ColorStyle::ObjectGradient
|
1
|
Objects are colored using a full gradient for each object regardless of object height. The gradient used is specified in seriesGradients , singleHighlightGradient and multiHighlightGradient 特性。 |
QGraphsTheme::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 seriesGradients , singleHighlightGradient and multiHighlightGradient 特性。 |
內置主題。
| 常量 | 值 | 描述 |
|---|---|---|
QGraphsTheme::Theme::QtGreen
|
0
|
A light theme with green as the base color. |
QGraphsTheme::Theme::QtGreenNeon
|
1
|
A light theme with green neon as the base color. |
QGraphsTheme::Theme::MixSeries
|
2
|
A mixed theme with various colors. |
QGraphsTheme::Theme::OrangeSeries
|
3
|
A theme with Orange as the base color. |
QGraphsTheme::Theme::YellowSeries
|
4
|
A theme with Yellow as the base color. |
QGraphsTheme::Theme::BlueSeries
|
5
|
A theme with Blue as the base color. |
QGraphsTheme::Theme::PurpleSeries
|
6
|
A theme with Purple as the base color. |
QGraphsTheme::Theme::GreySeries
|
7
|
A theme with Grey as the base color. |
QGraphsTheme::Theme::UserDefined
|
8
|
A user-defined theme. For more information, see Customizing Theme . |
This property holds the font to be used for labels on x axis.
訪問函數:
| QFont | axisXLabelFont () const |
| void | setAxisXLabelFont (const QFont & newAxisXLabelFont ) |
通知程序信號:
| void | axisXLabelFontChanged () |
This property holds the font to be used for labels on y axis.
訪問函數:
| QFont | axisYLabelFont () const |
| void | setAxisYLabelFont (const QFont & newAxisYLabelFont ) |
通知程序信號:
| void | axisYLabelFontChanged () |
This property holds the font to be used for labels on z axis.
訪問函數:
| QFont | axisZLabelFont () const |
| void | setAxisZLabelFont (const QFont & newAxisZLabelFont ) |
通知程序信號:
| void | axisZLabelFontChanged () |
This property holds the color of the view the graph is drawn into. The default value depends on colorScheme .
訪問函數:
| QColor | backgroundColor () const |
| void | setBackgroundColor (QColor newBackgroundColor ) |
通知程序信號:
| void | backgroundColorChanged () |
此特性保持背景是否可見。
The background is drawn by using the value of
backgroundColor
。默認值為
true
.
訪問函數:
| bool | isBackgroundVisible () const |
| void | setBackgroundVisible (bool newBackgroundVisible ) |
通知程序信號:
| void | backgroundVisibleChanged () |
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.
訪問函數:
| QList<QColor> | borderColors () const |
| void | setBorderColors (const QList<QColor> & newBorderColors ) |
通知程序信號:
| void | borderColorsChanged () |
This property holds the width of borders in graph if any The default value is
1.0
.
訪問函數:
| qreal | borderWidth () const |
| void | setBorderWidth (qreal newBorderWidth ) |
通知程序信號:
| void | borderWidthChanged () |
The color scheme of the graph in use.
訪問函數:
| QGraphsTheme::ColorScheme | colorScheme () const |
| void | setColorScheme (QGraphsTheme::ColorScheme newColorScheme ) |
通知程序信號:
| void | colorSchemeChanged () |
另請參閱 Qt::ColorScheme .
The style of the graph colors. One of QGraphsTheme::ColorStyle 枚舉值。
This value can be overridden by setting Abstract3DSeries.colorStyle explicitly in the series.
注意: This property does not have an effect in Qt Graphs for 2D.
訪問函數:
| QGraphsTheme::ColorStyle | colorStyle () const |
| void | setColorStyle (QGraphsTheme::ColorStyle newColorStyle ) |
通知程序信號:
| void | colorStyleChanged (QGraphsTheme::ColorStyle type ) |
另請參閱 QGraphsTheme::ColorStyle .
此特性保持是否繪製柵格綫。
This value affects all grid lines. The default value is
true
.
訪問函數:
| bool | isGridVisible () const |
| void | setGridVisible (bool newGridVisibility ) |
通知程序信號:
| void | gridVisibleChanged () |
此特性保持標簽背景的顔色。
不起作用若
labelBackgroundVisible
is
false
. The default value depends on
colorScheme
.
訪問函數:
| QColor | labelBackgroundColor () const |
| void | setLabelBackgroundColor (QColor newLabelBackgroundColor ) |
通知程序信號:
| void | labelBackgroundColorChanged () |
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
.
訪問函數:
| bool | isLabelBackgroundVisible () const |
| void | setLabelBackgroundVisible (bool newLabelBackgroundVisibility ) |
通知程序信號:
| void | labelBackgroundVisibleChanged () |
此特性保持是否為擁有背景的標簽繪製標簽邊框。
不起作用若
labelBackgroundVisible
is
false
。默認值為
true
.
訪問函數:
| bool | isLabelBorderVisible () const |
| void | setLabelBorderVisible (bool newLabelBorderVisibility ) |
通知程序信號:
| void | labelBorderVisibleChanged () |
此特性保持用於標簽的字體。
訪問函數:
| QFont | labelFont () const |
| void | setLabelFont (const QFont & newFont ) |
通知程序信號:
| void | labelFontChanged () |
此特性保持用於標簽的字體顔色。
If an axis has specified labelTextColor explicitly, this has no effect.
The default value depends on colorScheme .
訪問函數:
| QColor | labelTextColor () const |
| void | setLabelTextColor (QColor newLabelTextColor ) |
通知程序信號:
| void | labelTextColorChanged () |
This property holds whether labels are drawn at all.
若這為
false
, all other label properties have no effect. The default value is
true
.
訪問函數:
| bool | labelsVisible () const |
| void | setLabelsVisible (bool newLabelsVisibility ) |
通知程序信號:
| void | labelsVisibleChanged () |
This property holds the highlight color for selected objects.
Used if
selectionMode
擁有
QtGraphs3D::SelectionFlag::Row
or
QtGraphs3D::SelectionFlag::Column
flag set. The default value depends on
colorScheme
.
訪問函數:
| QColor | multiHighlightColor () const |
| void | setMultiHighlightColor (QColor newMultiHighlightColor ) |
通知程序信號:
| void | multiHighlightColorChanged (QColor color ) |
This property holds the highlight gradient for selected objects.
Used if
selectionMode
擁有
QtGraphs3D::SelectionFlag::Row
or
QtGraphs3D::SelectionFlag::Column
flag set. The default value depends on
colorScheme
.
通知程序信號:
| void | multiHighlightGradientQMLChanged () |
This property holds the color of the graph plot area background. The default value depends on colorScheme .
訪問函數:
| QColor | plotAreaBackgroundColor () const |
| void | setPlotAreaBackgroundColor (QColor newBackgroundColor ) |
通知程序信號:
| void | plotAreaBackgroundColorChanged () |
This property holds whether the plot area background is visible.
The background is drawn by using the value of
plotAreaBackgroundColor
。默認值為
true
.
訪問函數:
| bool | isPlotAreaBackgroundVisible () const |
| void | setPlotAreaBackgroundVisible (bool newBackgroundVisibility ) |
通知程序信號:
| void | plotAreaBackgroundVisibleChanged () |
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.
訪問函數:
| QList<QColor> | seriesColors () const |
| void | setSeriesColors (const QList<QColor> & newSeriesColors ) |
通知程序信號:
| void | seriesColorsChanged (const QList<QColor> & list ) |
This property holds the highlight color for a selected object.
Used if
selectionMode
擁有
QtGraphs3D::SelectionFlag::Item
flag set. The default value depends on
colorScheme
.
訪問函數:
| QColor | singleHighlightColor () const |
| void | setSingleHighlightColor (QColor newSingleHighlightColor ) |
通知程序信號:
| void | singleHighlightColorChanged (QColor color ) |
This property holds the highlight gradient for a selected object.
Used if
selectionMode
擁有
QtGraphs3D::SelectionFlag::Item
flag set. The default value depends on
colorScheme
.
通知程序信號:
| void | singleHighlightGradientQMLChanged () |
The type of the theme. If no type is set, the type is GraphsTheme.Theme.QtGreen . 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.
訪問函數:
| QGraphsTheme::Theme | theme () const |
| void | setTheme (QGraphsTheme::Theme newTheme , QGraphsTheme::ForceTheme force = ForceTheme::No) |
通知程序信號:
| void | themeChanged (QGraphsTheme::Theme theme ) |
Returns the list of series gradients used by theme.
另請參閱 setSeriesGradients ().
設置 newSeriesGradients as the series gradients for the theme.
另請參閱 seriesGradients ().