diff options
author | Keith Kyzivat <keith.kyzivat@qt.io> | 2021-06-02 13:43:37 -0400 |
---|---|---|
committer | Keith Kyzivat <keith.kyzivat@qt.io> | 2021-06-08 18:57:24 -0400 |
commit | 282f9aa1a5ca6cf2c853f20018a8cd6671f2934f (patch) | |
tree | 0ef1cd8278dd301df1fc6afc699f95049ad990a8 /src | |
parent | 7f940ae44f96be4228efb4620ab1d26dbf8a51e1 (diff) |
Update Qt Charts legend example to illustrate interactivity
Example cleaned up and organized, and interactive checkbox is added to
allow user to see how an interactive legend works.
Task-number: QTBUG-93477
Change-Id: I855283ad8fffd61b23cf021ab41530255abfbd47
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/charts/doc/images/examples_legend_detach.png | bin | 61273 -> 78304 bytes | |||
-rw-r--r-- | src/charts/doc/images/examples_legend_detach2.png | bin | 75296 -> 80767 bytes | |||
-rw-r--r-- | src/charts/doc/src/examples-legend.qdoc | 48 |
3 files changed, 34 insertions, 14 deletions
diff --git a/src/charts/doc/images/examples_legend_detach.png b/src/charts/doc/images/examples_legend_detach.png Binary files differindex 3376a4a0..867c17a6 100644 --- a/src/charts/doc/images/examples_legend_detach.png +++ b/src/charts/doc/images/examples_legend_detach.png diff --git a/src/charts/doc/images/examples_legend_detach2.png b/src/charts/doc/images/examples_legend_detach2.png Binary files differindex 5cc33819..5efe0d84 100644 --- a/src/charts/doc/images/examples_legend_detach2.png +++ b/src/charts/doc/images/examples_legend_detach2.png diff --git a/src/charts/doc/src/examples-legend.qdoc b/src/charts/doc/src/examples-legend.qdoc index c9d976d9..0d543c7d 100644 --- a/src/charts/doc/src/examples-legend.qdoc +++ b/src/charts/doc/src/examples-legend.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -32,16 +32,24 @@ \brief This example shows how to detach the legend from the chart and how to attach it back. - By default the chart draws the legend inside the same view with the chart. In some cases the - user may want to draw the legend to somewhere else. To make this possible the legend can be - detached from the chart. Detaching means that the chart doesn't draw the legend or try to - change its layout. Detached legend can then be drawn wherever the user wishes, for example, - in a different graphics scene. The behavior of the legend can be inspected by running the - legend example. - In the example we use the bar series where we add or remove the bar sets. The legend reflects - the changes in series. The legend can be detached or attached back to the chart and its - alignment can be modified. - When the legend is detached, it can be resized and positioned freely. + By default, the chart draws the legend inside the same graphics view the chart is contained + within. In some cases, the user may want to draw the legend somewhere else. To make this + possible, the legend can be detached from the chart. Detaching means that the legend is no + longer fixed to an edge of the chart, and the chart no longer controls the legend's layout. + Instead, the legend geometry is controlled by the user, allowing free control of the location + and size of the legend. This can be floating atop the content of the chart, or even drawn in a + different graphics scene. The behavior of the legend can be tested by running this example. + + In this example we show a bar series, allowing bar sets to be added or removed interactively. + The legend reflects the changes in series as bar sets are added and/or removed. The attachment + of the legend, its alignment, and its ability to be moved and resized can be controlled using + methods in \c QLegend. + + When the legend is detached, it can be resized and positioned freely. If the interactive + feature of the legend is enabled, the legend can be freely dragged and resized by the user. + If the user drags the legend off of any side of the chart, it will automatically re-attach to + that side of the chart. + \image examples_legend_detach.png \image examples_legend_detach2.png @@ -54,15 +62,27 @@ \snippet legend/mainwidget.cpp 1 - This snippet shows how to detach the legend from the chart. After detaching, we turn its background to visible and set a different color to it. This makes it easier to see how the items inside the legend are arranged in detached mode. + This snippet shows how to detach the legend from the chart. \snippet legend/mainwidget.cpp 2 - Here we attach the legend back to the chart. The background is turned invisible. + Here we reattach the legend to the chart. The background is turned invisible. \snippet legend/mainwidget.cpp 3 - This shows how we set the detached legend dimensions. After setting the new values, we call update to show changes on screen. + Here we connect to the signal emitted when the legend is detached or attached, turning its + background on when detached and off when attached. This makes it easier to see how the + items inside the legend are arranged when it is detached. \snippet legend/mainwidget.cpp 4 + + This shows how to make the legend interactive to the user using a pointing device such as a + mouse. + + \snippet legend/mainwidget.cpp 5 + + This shows how we set the detached legend dimensions if the legend is not interactive. After + setting the new values, we call update to show changes on screen. + + \snippet legend/mainwidget.cpp 6 */ |