6.0.0-rc4Source

QChartView Class

The QChartView class is a widget that shows a chart. More…

Header#include <QChartView>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Types

enumRubberBand
typedefRubberBands

Public Functions

QChartView(QWidget *parent = nullptr)
QChartView(QChart *chart, QWidget *parent = nullptr)
~QChartView()
voidsetRubberBand(const RubberBands &rubberBands)
RubberBandsrubberBand() const
voidsetChart(QChart *chart)
QChart *chart() const
voidsetRenderHint(QPainter::RenderHint hint, bool enabled = true)
voidsetRenderHints(QPainter::RenderHints hints)
QPainter::RenderHintsrenderHints() const

Reimplemented Public Functions

QSizesizeHint() const

Reimplemented Protected Functions

Detailed Description

The view draws its chart over its whole area, and resizes the chart with it. It owns the chart.

auto *view = new QChartView(lineChart(&live));
view->setRubberBand(QChartView::HorizontalRubberBand);
grid->addWidget(view, 0, 0);

The mouse reaches the series: clicking a bar emits QBarSet::clicked(), hovering over a slice emits QPieSlice::hovered(), and so on. With setRubberBand(), dragging with the left button zooms into the rectangle dragged over, and clicking the right button zooms out.

See also QChart.

Differences from Qt

The view is a QWidget, not a QGraphicsView: there is no scene, and the chart cannot be moved or transformed in it. The chart is always drawn antialiased; the render hints are kept but not used.

Member Type Documentation

enum QChartView::RubberBand

How dragging with the mouse zooms.

ConstantDescription
QChartView::NoRubberBandDragging does not zoom.
QChartView::VerticalRubberBandDragging selects a range of the vertical axes.
QChartView::HorizontalRubberBandDragging selects a range of the horizontal axes.
QChartView::RectangleRubberBandDragging selects a rectangle.
QChartView::ClickThroughRubberBandCombined with one of the others: presses and releases reach the series too.

typedef QChartView::RubberBands

A QFlags of RubberBand values.

Member Function Documentation

[explicit] QChartView::QChartView(QWidget *parent = nullptr)

Constructs a view with the given parent, showing a new, empty chart.

[explicit] QChartView::QChartView(QChart *chart, QWidget *parent = nullptr)

Constructs a view with the given parent that shows chart and takes ownership of it.

[override] QChartView::~QChartView()

Destroys the view and its chart.

QChart * QChartView::chart() const

Returns the chart the view shows.

[override, protected] void QChartView::leaveEvent(QEvent *event)

Reimplements QWidget::leaveEvent().

Tells the series under the mouse that it is no longer hovered. event is not used.

[override, protected] void QChartView::mouseDoubleClickEvent(QMouseEvent *event)

Reimplements QWidget::mouseDoubleClickEvent().

Passes the double click of event to the series under the mouse.

[override, protected] void QChartView::mouseMoveEvent(QMouseEvent *event)

Reimplements QWidget::mouseMoveEvent().

Stretches the rubber band, or tells the series under the mouse that it is hovered; event has the position.

[override, protected] void QChartView::mousePressEvent(QMouseEvent *event)

Reimplements QWidget::mousePressEvent().

Starts a rubber band, or passes the press of event to the series under the mouse.

[override, protected] void QChartView::mouseReleaseEvent(QMouseEvent *event)

Reimplements QWidget::mouseReleaseEvent().

Zooms into the rubber band, zooms out on a right click, or passes the release of event to the series under the mouse.

[override, protected] void QChartView::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

Draws the chart. event is not used.

QPainter::RenderHints QChartView::renderHints() const

Returns the render hints. The default is QPainter::Antialiasing.

[override, protected] void QChartView::resizeEvent(QResizeEvent *event)

Reimplements QWidget::resizeEvent().

Resizes the chart to the view. event is not used.

RubberBands QChartView::rubberBand() const

Returns how dragging zooms. The default is NoRubberBand.

void QChartView::setChart(QChart *chart)

Shows chart instead of the current one, and takes ownership of it. The view gives up the previous chart without deleting it, unless the view made it itself. A nullptr leaves the view empty.

void QChartView::setRenderHint(QPainter::RenderHint hint, bool enabled = true)

Turns the render hint hint on if enabled is true, and off otherwise. Nt keeps the hints; the chart is always antialiased.

void QChartView::setRenderHints(QPainter::RenderHints hints)

Sets the render hints to hints.

void QChartView::setRubberBand(const RubberBands &rubberBands)

Sets how dragging zooms to rubberBands.

[override] QSize QChartView::sizeHint() const

Reimplements QWidget::sizeHint().

Returns 400 by 300 pixels.