##// END OF EJS Templates
Documented customcolors example
Tero Ahola -
r499:cdecb97c9343
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,21
1 /*!
2 \example examples/customcolors
3 \title CustomColors Example
4 \subtitle
5
6 The example shows how to customize different visual elements on a typical chart i.e. customize
7 the following chart:
8 \image custom_colors1.jpg
9
10 to look like this instead:
11 \image custom_colors2.jpg
12
13 Customize chart background with the company specific colors:
14 \snippet ../examples/customcolors/mainwindow.cpp 1
15
16 Customize chart axes:
17 \snippet ../examples/customcolors/mainwindow.cpp 2
18
19 Customize pen and brush of all the series we have:
20 \snippet ../examples/customcolors/mainwindow.cpp 3
21 */ No newline at end of file
@@ -23,6 +23,7
23 23 <li><a href="example-splinechart.html">Spline Chart example</a></li>
24 24 <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li>
25 25 <li><a href="example-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown example</a></li>
26 <li><a href="examples-customcolors.html">Customizing colors example</a></li>
26 27 </ul>
27 28 </td>
28 29 </tr>
@@ -15,7 +15,7 MainWindow::MainWindow(QWidget *parent)
15 15 // Here's the set of company's colors used throughout the example
16 16 m_companyColor1 = "#b90020";
17 17 m_companyColor2 = "#6d0013";
18 m_companyColor3 = "#d5d5f5";
18 m_companyColor3 = "#f5d5d5";
19 19 m_companyColor4 = "#fcfcfc";
20 20
21 21 resize(400, 300);
@@ -61,8 +61,8 MainWindow::~MainWindow()
61 61
62 62 void MainWindow::customize()
63 63 {
64 // Customize chart background
65 // Use a gradient from color 3 to color 4 for chart background
64 //! [1]
65 // Use a gradient from "color 3" to "color 4" for chart background
66 66 QLinearGradient chartGradient(0, 0, 0, 300);
67 67 chartGradient.setColorAt(0.0, m_companyColor3);
68 68 chartGradient.setColorAt(0.5, m_companyColor4);
@@ -70,22 +70,29 void MainWindow::customize()
70 70 m_chartView->setChartBackgroundBrush(chartGradient);
71 71 m_chartView->setBackgroundBrush(m_companyColor4);
72 72 m_chartView->setChartTitleBrush(m_companyColor1);
73 //! [1]
73 74
74 // Customize chart axis
75 //! [2]
75 76 QPen color1Pen(m_companyColor1, 4.0);
76 77 m_chartView->axisX()->setAxisPen(color1Pen);
77 78 m_chartView->axisY()->setAxisPen(color1Pen);
79 //! [2]
78 80
79 // Customize series
81 //! [3]
82 // Customize pen of the line series
80 83 m_line->setPen(color1Pen);
84
85 // Customize pen and brush for the scatter
81 86 m_scatter->setPen(color1Pen);
82 87 m_scatter->setBrush(m_companyColor3);
88
89 // Customize pen and brush for the pie
83 90 for (int i(0); i < m_pie->slices().count(); i++) {
84 91 Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1);
85 92 m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style));
86 93 m_pie->slices().at(i)->setSlicePen(color1Pen);
87 94 }
88
95 //! [3]
89 96
90 97 // Calculate new colors to be used on the next update for the series
91 98 m_companyColor1.setRed((m_companyColor1.red() + 25) % 255);
General Comments 0
You need to be logged in to leave comments. Login now