QChartView Class
The QChartView class is a widget that shows a chart. More…
| Header | #include <QChartView> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Types
| enum | RubberBand |
| typedef | RubberBands |
Public Functions
| QChartView(QWidget *parent = nullptr) | |
| QChartView(QChart *chart, QWidget *parent = nullptr) | |
| ~QChartView() | |
| void | setRubberBand(const RubberBands &rubberBands) |
| RubberBands | rubberBand() const |
| void | setChart(QChart *chart) |
| QChart * | chart() const |
| void | setRenderHint(QPainter::RenderHint hint, bool enabled = true) |
| void | setRenderHints(QPainter::RenderHints hints) |
| QPainter::RenderHints | renderHints() const |
Reimplemented Public Functions
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | resizeEvent(QResizeEvent *event) |
| void | mousePressEvent(QMouseEvent *event) |
| void | mouseMoveEvent(QMouseEvent *event) |
| void | mouseReleaseEvent(QMouseEvent *event) |
| void | mouseDoubleClickEvent(QMouseEvent *event) |
| void | leaveEvent(QEvent *event) |
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.
| Constant | Description |
|---|---|
QChartView::NoRubberBand | Dragging does not zoom. |
QChartView::VerticalRubberBand | Dragging selects a range of the vertical axes. |
QChartView::HorizontalRubberBand | Dragging selects a range of the horizontal axes. |
QChartView::RectangleRubberBand | Dragging selects a rectangle. |
QChartView::ClickThroughRubberBand | Combined with one of the others: presses and releases reach the series too. |
typedef QChartView::RubberBands
A QFlags of RubberBand values.
Member Function Documentation
QChartView::QChartView(QWidget *parent = nullptr)
Constructs a view with the given parent, showing a new, empty chart.
QChartView::QChartView(QChart *chart, QWidget *parent = nullptr)
Constructs a view with the given parent that shows chart and takes ownership of it.
QChartView::~QChartView()
Destroys the view and its chart.
QChart * QChartView::chart() const
Returns the chart the view shows.
void QChartView::leaveEvent(QEvent *event)
Reimplements QWidget::leaveEvent().
Tells the series under the mouse that it is no longer hovered. event is not used.
void QChartView::mouseDoubleClickEvent(QMouseEvent *event)
Reimplements QWidget::mouseDoubleClickEvent().
Passes the double click of event to the series under the mouse.
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.
void QChartView::mousePressEvent(QMouseEvent *event)
Reimplements QWidget::mousePressEvent().
Starts a rubber band, or passes the press of event to the series under the mouse.
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.
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.
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.
QSize QChartView::sizeHint() const
Reimplements QWidget::sizeHint().
Returns 400 by 300 pixels.