##// END OF EJS Templates
combined clicked and rightclicked events of legend to one event with parameter
combined clicked and rightclicked events of legend to one event with parameter

File last commit:

r506:c57adf7875bb
r567:17f0257049a1
Show More
mainwindow.cpp
107 lines | 3.2 KiB | text/x-c | CppLexer
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 #include "mainwindow.h"
#include <qchartview.h>
#include <qpieseries.h>
#include <qpieslice.h>
#include <qlineseries.h>
#include <qscatterseries.h>
#include <qchartaxis.h>
#include <QDebug>
QTCOMMERCIALCHART_USE_NAMESPACE
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Here's the set of company's colors used throughout the example
m_companyColor1 = "#b90020";
m_companyColor2 = "#6d0013";
Tero Ahola
Documented customcolors example
r499 m_companyColor3 = "#f5d5d5";
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_companyColor4 = "#fcfcfc";
resize(400, 300);
Tero Ahola
Chart title font color
r495 setWindowFlags(Qt::FramelessWindowHint);
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491
// Create chart view
Tero Ahola
Improved custom color example documentation
r506 //! [4]
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_chartView = new QChartView(this);
Tero Ahola
Improved custom color example documentation
r506 m_chartView->setChartTheme(QChart::ChartThemeScientific);
//! [4]
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 setCentralWidget(m_chartView);
m_chartView->setChartTitle("Custom colors example");
m_chartView->setRenderHint(QPainter::Antialiasing);
// Create line series
m_line = new QLineSeries();
m_line->add(0.0, 1.1);
m_line->add(1.0, 2.3);
m_line->add(2.0, 2.1);
m_line->add(3.0, 3.3);
m_chartView->addSeries(m_line);
// Create scatter series with the same data
m_scatter = new QScatterSeries();
m_scatter->add(m_line->data());
m_chartView->addSeries(m_scatter);
Tero Ahola
Chart title font color
r495 // Create pie series with different data
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_pie = new QPieSeries();
m_pie->add(1.1, "1");
m_pie->add(2.1, "2");
m_pie->add(3.0, "3");
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 m_pie->setPiePosition(0.7, 0.7);
m_pie->setPieSize(0.5);
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_chartView->addSeries(m_pie);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize()));
m_timer.setInterval(1500);
m_timer.setSingleShot(false);
m_timer.start();
}
MainWindow::~MainWindow()
{
}
void MainWindow::customize()
{
Tero Ahola
Documented customcolors example
r499 //! [1]
// Use a gradient from "color 3" to "color 4" for chart background
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 QLinearGradient chartGradient(0, 0, 0, 300);
chartGradient.setColorAt(0.0, m_companyColor3);
chartGradient.setColorAt(0.5, m_companyColor4);
chartGradient.setColorAt(1.0, m_companyColor3);
m_chartView->setChartBackgroundBrush(chartGradient);
m_chartView->setBackgroundBrush(m_companyColor4);
Tero Ahola
Chart title font color
r495 m_chartView->setChartTitleBrush(m_companyColor1);
Tero Ahola
Documented customcolors example
r499 //! [1]
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491
Tero Ahola
Documented customcolors example
r499 //! [2]
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 QPen color1Pen(m_companyColor1, 4.0);
m_chartView->axisX()->setAxisPen(color1Pen);
m_chartView->axisY()->setAxisPen(color1Pen);
Tero Ahola
Documented customcolors example
r499 //! [2]
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491
Tero Ahola
Documented customcolors example
r499 //! [3]
// Customize pen of the line series
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_line->setPen(color1Pen);
Tero Ahola
Documented customcolors example
r499
// Customize pen and brush for the scatter
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 m_scatter->setPen(color1Pen);
m_scatter->setBrush(m_companyColor3);
Tero Ahola
Documented customcolors example
r499
// Customize pen and brush for the pie
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 for (int i(0); i < m_pie->slices().count(); i++) {
Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1);
m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style));
m_pie->slices().at(i)->setSlicePen(color1Pen);
}
Tero Ahola
Documented customcolors example
r499 //! [3]
Tero Ahola
Chart title font color
r495
Tero Ahola
Added data getter for XY series; example for customizing the looks
r491 // Calculate new colors to be used on the next update for the series
m_companyColor1.setRed((m_companyColor1.red() + 25) % 255);
m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255);
m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255);
m_companyColor2.setRed((m_companyColor2.red() + 25) % 255);
m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255);
m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255);
}