summaryrefslogtreecommitdiffstats
path: root/src/charts/doc/src/examples-legend.qdoc
blob: 3b14a3da9e8fe9475f783c2f9c965e8d19e99961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/******************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Charts module.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
******************************************************************************/

/*!
    \example legend
    \title Legend Example
    \ingroup qtcharts_examples

    \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.

    \image examples_legend_detach.png
    \image examples_legend_detach2.png

    Here we turn the legend visible and set its alignment to the bottom of the chart.

    \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.

    \snippet legend/mainwidget.cpp 2

    Here we attach the legend back 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.

    \snippet legend/mainwidget.cpp 4
*/