Qt 5.7 | Qt Charts | C++ Classes | QChartView

Qt 5.7.1 Reference Documentation

# QChartView Class

Standalone charting widget. More...

Header: | #include <QChartView>

- List of all members, including inherited members

## Public Types

enum | RubberBand { NoRubberBand, VerticalRubberBand, HorizontalRubberBand, RectangleRubberBand }
flags | RubberBands

## Public Functions

| QChartView(QWidget *parent = Q_NULLPTR)
| QChartView(QChart *chart, QWidget *parent = Q_NULLPTR)
| ~QChartView()
QChart * | chart() const
RubberBands | rubberBand() const
void | setChart(QChart *chart)
void | setRubberBand(const RubberBands &rubberBand)

## Protected Functions

void | mouseMoveEvent(QMouseEvent *event)
void | mousePressEvent(QMouseEvent *event)
void | mouseReleaseEvent(QMouseEvent *event)
void | resizeEvent(QResizeEvent *event)

## Detailed Description

Standalone charting widget.

QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. If you want to display a chart in your existing QGraphicsScene, you need to use the QChart (or QPolarChart) class instead.

See also QChart and QPolarChart.

## Member Type Documentation

### enum QChartView::RubberBand
flags QChartView::RubberBands

This enum describes the different types of rubber bands that can be used for zoom rect selection

Constant | Value
--- | ---
`QChartView::NoRubberBand` | `0x0`
`QChartView::VerticalRubberBand` | `0x1`
`QChartView::HorizontalRubberBand` | `0x2`
`QChartView::RectangleRubberBand` | `0x3`

The RubberBands type is a typedef for QFlags<RubberBand>. It stores an OR combination of RubberBand values.

## Member Function Documentation

### QChartView::QChartView(QWidget *parent = Q_NULLPTR)

Constructs a chartView object with parent parent.

### QChartView::QChartView(QChart *chart, QWidget *parent = Q_NULLPTR)

Constructs a chartview object with parent parent to display a chart. Ownership of the chart is passed to chartview.

### QChartView::~QChartView()

Destroys the chartview object and the associated chart.

### QChart *QChartView::chart() const

Returns the pointer to the associated chart.

See also setChart().

### `[protected]` void QChartView::mouseMoveEvent(QMouseEvent *event)

If the rubber band rectange has been displayed in pressEvent then event data is used to update the rubber band geometry. Otherwise the default QGraphicsView::mouseMoveEvent implementation is called.

### `[protected]` void QChartView::mousePressEvent(QMouseEvent *event)

If Left mouse button is pressed and the rubber band is enabled the event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. If different mouse button is pressed and/or the rubber band is disabled then the event is passed to QGraphicsView::mousePressEvent() implementation.

### `[protected]` void QChartView::mouseReleaseEvent(QMouseEvent *event)

If left mouse button is released and the rubber band is enabled then event is accepted and the view is zoomed into the rect specified by the rubber band. If it is a right mouse button event then the view is zoomed out.

### `[protected]` void QChartView::resizeEvent(QResizeEvent *event)

Resizes and updates the chart area using the event data

### RubberBands QChartView::rubberBand() const

Returns the rubber band flags that are currently being used by the widget.

See also setRubberBand().

### void QChartView::setChart(QChart *chart)

Sets the current chart to chart. Ownership of the new chart is passed to chartview and ownership of the previous chart is released.

To avoid memory leaks users need to make sure the previous chart is deleted.

See also chart().

### void QChartView::setRubberBand(const RubberBands &rubberBand)

Sets the rubber band flags to rubberBand. Selected flags determine the way zooming is performed.

Note: Rubber band zooming is not supported for polar charts.

See also rubberBand().