##// END OF EJS Templates
Introducing vertical and horizontal factors to control the position of the pie.
Introducing vertical and horizontal factors to control the position of the pie.

File last commit:

r394:9882bdf19567
r454:06980850b7dd
Show More
mainwindow.cpp
51 lines | 1.4 KiB | text/x-c | CppLexer
#include "mainwindow.h"
#include <qchartglobal.h>
#include <qchartview.h>
#include <QDebug>
QTCOMMERCIALCHART_USE_NAMESPACE
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
resize(400, 300);
setWindowFlags(Qt::FramelessWindowHint);
QChartView *chartView = new QChartView(this);
chartView->setChartTitle("Click to play with points");
chartView->setRenderHint(QPainter::Antialiasing);
setCentralWidget(chartView);
m_scatter = new QScatterSeries();
for(qreal x(0.5); x <= 5.0; x += 0.5) {
for(qreal y(0.5); y <= 5.0; y += 0.5) {
*m_scatter << QPointF(x, y);
}
}
chartView->addSeries(m_scatter);
// Add two more series
m_scatter2 = new QScatterSeries();
chartView->addSeries(m_scatter2);
m_scatter3 = new QScatterSeries();
chartView->addSeries(m_scatter3);
connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(clickPoint(QPointF)));
}
MainWindow::~MainWindow()
{
}
void MainWindow::clickPoint(QPointF coordinate)
{
// Remove the clicked point from the series and add points to the two other series we have
int index = m_scatter->closestPoint(coordinate);
QPointF point = m_scatter->data().at(index);
Q_ASSERT(m_scatter->removeAt(index));
point.rx() += 0.25;
point.ry() += 0.25;
*m_scatter2 << point;
point.ry() -= 0.25;
*m_scatter3 << point;
}