main.cpp
51 lines
| 1.4 KiB
| text/x-c
|
CppLexer
Tero Ahola
|
r123 | #include <QtGui/QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartglobal.h> | ||||
Michal Klocek
|
r136 | #include <qchartview.h> | ||
Tero Ahola
|
r123 | #include <qscatterseries.h> | ||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
Tero Ahola
|
r300 | //! [1] | ||
// Create chart view | ||||
Tero Ahola
|
r260 | QChartView *chartView = new QChartView(); | ||
Tero Ahola
|
r397 | chartView->setRenderHint(QPainter::Antialiasing); | ||
chartView->setChartTheme(QChart::ChartThemeScientific); | ||||
// Add scatter series with linear test data with random "noise" | ||||
Tero Ahola
|
r180 | QScatterSeries *scatter = new QScatterSeries(); | ||
Tero Ahola
|
r397 | for (qreal i(0.0); i < 20; i += 0.25) { | ||
qreal x = i + (qreal)(rand() % 100) / 100.0; | ||||
qreal y = i + (qreal)(rand() % 100) / 100.0; | ||||
(*scatter) << QPointF(x, y); | ||||
} | ||||
Tero Ahola
|
r260 | // Chart takes ownership | ||
chartView->addSeries(scatter); | ||||
Tero Ahola
|
r278 | //! [1] | ||
Tero Ahola
|
r123 | |||
Tero Ahola
|
r300 | // And more | ||
Tero Ahola
|
r397 | //! [2] | ||
//*scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); | ||||
//! [2] | ||||
Tero Ahola
|
r300 | |||
Tero Ahola
|
r397 | //! [3] | ||
QBrush brush(QColor(255, 0, 0, 80), Qt::SolidPattern); | ||||
Tero Ahola
|
r358 | scatter->setBrush(brush); | ||
Tero Ahola
|
r397 | QPen pen(QColor(0, 255, 0, 60), 3); | ||
Tero Ahola
|
r358 | scatter->setPen(pen); | ||
scatter->setShape(QScatterSeries::MarkerShapeRectangle); | ||||
Tero Ahola
|
r397 | scatter->setSize(15.0); | ||
//! [3] | ||||
Tero Ahola
|
r123 | |||
// Use the chart widget as the central widget | ||||
QMainWindow w; | ||||
Tero Ahola
|
r394 | w.resize(400, 300); | ||
Tero Ahola
|
r260 | w.setCentralWidget(chartView); | ||
Tero Ahola
|
r394 | w.setWindowFlags(Qt::FramelessWindowHint); | ||
Tero Ahola
|
r123 | w.show(); | ||
return a.exec(); | ||||
} | ||||