@@ -36,7 +36,12 int main(int argc, char *argv[]) | |||
|
36 | 36 | chartView->setTitle("Custom color line chart example"); |
|
37 | 37 | chartView->addSeries(series0); |
|
38 | 38 | chartView->addSeries(series1); |
|
39 | chartView->setBackground(Qt::blue,Qt::yellow,QChart::HorizonatlGradientOrientation); | |
|
39 | ||
|
40 | QLinearGradient backgroundGradient; | |
|
41 | backgroundGradient.setColorAt(0.0, Qt::blue); | |
|
42 | backgroundGradient.setColorAt(1.0, Qt::yellow); | |
|
43 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
44 | chartView->setChartBackgroundBrush(backgroundGradient); | |
|
40 | 45 | |
|
41 | 46 | window.setCentralWidget(chartView); |
|
42 | 47 | window.resize(400, 300); |
@@ -71,7 +71,7 void QChart::addSeries(QChartSeries* series) | |||
|
71 | 71 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,0,this); | |
|
75 | 75 | |
|
76 | 76 | m_chartItems << item; |
|
77 | 77 | // TODO: |
@@ -240,12 +240,12 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra | |||
|
240 | 240 | m_bacgroundOrinetation = orientation; |
|
241 | 241 | m_backgroundGradient.setColorAt(0.0, startColor); |
|
242 | 242 | m_backgroundGradient.setColorAt(1.0, endColor); |
|
243 | m_backgroundGradient.setStart(0,0); | |
|
243 | m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
244 | 244 | |
|
245 | 245 | if(orientation == VerticalGradientOrientation){ |
|
246 |
m_backgroundGradient.setFinalStop(0, |
|
|
246 | m_backgroundGradient.setFinalStop(0,1); | |
|
247 | 247 | }else{ |
|
248 |
m_backgroundGradient.setFinalStop( |
|
|
248 | m_backgroundGradient.setFinalStop(1,0); | |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | m_backgroundItem->setBrush(m_backgroundGradient); |
@@ -253,6 +253,30 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra | |||
|
253 | 253 | m_backgroundItem->update(); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
|
257 | { | |
|
258 | ||
|
259 | if(!m_backgroundItem){ | |
|
260 | m_backgroundItem = new QGraphicsRectItem(this); | |
|
261 | m_backgroundItem->setZValue(-1); | |
|
262 | } | |
|
263 | ||
|
264 | m_backgroundItem->setBrush(brush); | |
|
265 | m_backgroundItem->update(); | |
|
266 | } | |
|
267 | ||
|
268 | void QChart::setChartBackgroundPen(const QPen& pen) | |
|
269 | { | |
|
270 | ||
|
271 | if(!m_backgroundItem){ | |
|
272 | m_backgroundItem = new QGraphicsRectItem(this); | |
|
273 | m_backgroundItem->setZValue(-1); | |
|
274 | } | |
|
275 | ||
|
276 | m_backgroundItem->setPen(pen); | |
|
277 | m_backgroundItem->update(); | |
|
278 | } | |
|
279 | ||
|
256 | 280 | void QChart::setTitle(const QString& title,const QFont& font) |
|
257 | 281 | { |
|
258 | 282 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
@@ -390,11 +414,6 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |||
|
390 | 414 | //recalculate background gradient |
|
391 | 415 | if (m_backgroundItem) { |
|
392 | 416 | m_backgroundItem->setRect(rect); |
|
393 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) | |
|
394 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); | |
|
395 | else | |
|
396 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); | |
|
397 | m_backgroundItem->setBrush(m_backgroundGradient); | |
|
398 | 417 | } |
|
399 | 418 | |
|
400 | 419 | // resize and reposition childs |
@@ -63,6 +63,9 public: | |||
|
63 | 63 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
64 | 64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); |
|
65 | 65 | |
|
66 | void setChartBackgroundBrush(const QBrush& brush); | |
|
67 | void setChartBackgroundPen(const QPen& pen); | |
|
68 | ||
|
66 | 69 | void zoomInToRect(const QRectF& rectangle); |
|
67 | 70 | void zoomIn(); |
|
68 | 71 | void zoomOut(); |
@@ -74,4 +74,12 void QChartView::setBackground(const QColor& startColor, const QColor& endColor, | |||
|
74 | 74 | m_chart->setBackground(startColor,endColor,orientation); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
|
78 | { | |
|
79 | m_chart->setChartBackgroundBrush(brush); | |
|
80 | } | |
|
81 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
|
82 | { | |
|
83 | m_chart->setChartBackgroundPen(pen); | |
|
84 | } | |
|
77 | 85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -27,7 +27,14 public: | |||
|
27 | 27 | |
|
28 | 28 | int margin() const; |
|
29 | 29 | void setTitle(const QString& title); |
|
30 | ||
|
31 | //Obsolete | |
|
30 | 32 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation); |
|
33 | ||
|
34 | ||
|
35 | void setChartBackgroundBrush(const QBrush& brush); | |
|
36 | void setChartBackgroundPen(const QPen& pen); | |
|
37 | ||
|
31 | 38 | void zoomInToRect(const QRect& rectangle); |
|
32 | 39 | void zoomIn(); |
|
33 | 40 | void zoomOut(); |
General Comments 0
You need to be logged in to leave comments.
Login now