QTradingView 1.0.0
A high-performance charting library built with C++ and Qt.
Loading...
Searching...
No Matches
QTradingView::Chart Class Reference

Top level chart container for QTradingView. More...

#include <Chart.h>

Inheritance diagram for QTradingView::Chart:

Public Member Functions

 Chart (QWidget *parent=nullptr)
 Constructs a Chart object.
 
 ~Chart () override
 Destroys the Chart object.
 
std::shared_ptr< PaneaddPane (double heightRatio=1.0)
 Adds a new pane to the chart.
 
void removePane (Pane *pane)
 Removes a pane from the chart.
 
PanemainPane ()
 Returns the main (first) pane of the chart.
 
std::vector< Pane * > panes () const
 Returns all the panes in the chart.
 
ViewPortviewport ()
 Access the chart's viewport.
 
void setTheme (const ChartTheme &theme)
 Sets the chart theme.
 
const ChartThemetheme () const
 Gets the current chart theme.
 
void calculateLayout ()
 Recalculates the layout of all panes and axes based on the current chart size.
 
void pan (int indexDelta)
 Pans the chart horizontally by a number of data points.
 
void zoom (int indexDelta, int anchorIndex)
 Zooms the chart horizontally by changing the number of visible data points.
 
void fitToData ()
 Fits the chart view to show all available data, capped by the maximum allowed bars.
 
void showLastNPoints (int n)
 Shows the last N data points in the main pane, capped by the maximum allowed bars.
 
void show ()
 Shows the chart with the default number of data points (e.g., last 300).
 
void setCrosshairVisible (bool visible)
 Sets the crosshair visibility.
 
bool isCrosshairVisible () const
 Checks if the crosshair is currently visible.
 
void setCrosshairPosition (const QPointF &position)
 Sets the crosshair position in chart coordinates.
 
QPointF crosshairPosition () const
 Gets the current crosshair position in chart coordinates.
 
AxisRendereraxis ()
 Access the axis renderer for customization.
 
GridRenderergrid ()
 Access the grid renderer for customization.
 
CrosshairRenderercrosshair ()
 Access the crosshair renderer for customization.
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void leaveEvent (QEvent *event) override
 
bool event (QEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 

Detailed Description

Top level chart container for QTradingView.

The Chart class manages multiple panes, handles zoom/pan interactions, crosshair rendering, and coordinate all series rendering. It provides a high-performance, interactive charting experience similar to TradingView lightweight charts.

QApplication app(argc, argv);
auto chart = new QTradingView::Chart();
auto pane = chart->addPane(1.0);
pane->addSeries(std::make_shared<QTradingView::CandleStickSeries>(data));
chart->show();
app.exec();
Top level chart container for QTradingView.
Definition Chart.h:74

Constructor & Destructor Documentation

◆ Chart()

QTradingView::Chart::Chart ( QWidget *  parent = nullptr)
explicit

Constructs a Chart object.

Parameters
parentOptional parent widget.

Member Function Documentation

◆ addPane()

std::shared_ptr< Pane > QTradingView::Chart::addPane ( double  heightRatio = 1.0)

Adds a new pane to the chart.

Parameters
heightRatioRelative weight of the pane compared to others (default 1.0).
Returns
Shared pointer to the newly created Pane.

◆ axis()

AxisRenderer & QTradingView::Chart::axis ( )

Access the axis renderer for customization.

Returns
Reference to the axis renderer.

◆ crosshair()

CrosshairRenderer & QTradingView::Chart::crosshair ( )

Access the crosshair renderer for customization.

Returns
Reference to the crosshair renderer.

◆ crosshairPosition()

QPointF QTradingView::Chart::crosshairPosition ( ) const

Gets the current crosshair position in chart coordinates.

Returns
Position in pixels relative to the chart widget.

◆ grid()

GridRenderer & QTradingView::Chart::grid ( )

Access the grid renderer for customization.

Returns
Reference to the grid renderer.

◆ isCrosshairVisible()

bool QTradingView::Chart::isCrosshairVisible ( ) const

Checks if the crosshair is currently visible.

Returns
True if the crosshair is visible, false otherwise.

◆ mainPane()

Pane * QTradingView::Chart::mainPane ( )

Returns the main (first) pane of the chart.

Returns
Pointer to the main Pane.

◆ pan()

void QTradingView::Chart::pan ( int  indexDelta)

Pans the chart horizontally by a number of data points.

Parameters
indexDeltaNumber of indices to pan (positive for right, negative for left).

◆ panes()

std::vector< Pane * > QTradingView::Chart::panes ( ) const

Returns all the panes in the chart.

Returns
Vector of pointers to all panes.

◆ removePane()

void QTradingView::Chart::removePane ( Pane pane)

Removes a pane from the chart.

Parameters
panePointer to the pane to remove.

◆ setCrosshairPosition()

void QTradingView::Chart::setCrosshairPosition ( const QPointF &  position)

Sets the crosshair position in chart coordinates.

Parameters
positionPosition in pixels relative to the chart widget.

◆ setCrosshairVisible()

void QTradingView::Chart::setCrosshairVisible ( bool  visible)

Sets the crosshair visibility.

Parameters
visibleTrue to show the crosshair, false to hide.

◆ setTheme()

void QTradingView::Chart::setTheme ( const ChartTheme theme)

Sets the chart theme.

Parameters
themeChartTheme object defining colors and styles.

◆ showLastNPoints()

void QTradingView::Chart::showLastNPoints ( int  n)

Shows the last N data points in the main pane, capped by the maximum allowed bars.

Parameters
nNumber of points to display.

◆ theme()

const ChartTheme & QTradingView::Chart::theme ( ) const

Gets the current chart theme.

Returns
Reference to the current ChartTheme.

◆ viewport()

ViewPort & QTradingView::Chart::viewport ( )

Access the chart's viewport.

Returns
Reference to the ViewPort object.

◆ zoom()

void QTradingView::Chart::zoom ( int  indexDelta,
int  anchorIndex 
)

Zooms the chart horizontally by changing the number of visible data points.

Parameters
indexDeltaChange in the number of visible indices (positive to zoom out, negative to zoom in).
anchorIndexData index to anchor the zoom operation.

The documentation for this class was generated from the following files: