diff --git a/example/axischart/main.cpp b/example/axischart/main.cpp index a2db460..abdb7c3 100644 --- a/example/axischart/main.cpp +++ b/example/axischart/main.cpp @@ -38,14 +38,20 @@ int main(int argc, char *argv[]) chartView->setTitle("Basic line chart example"); chartView->addSeries(series0); chartView->addSeries(series1); - chartView->setChartBackgroundBrush(Qt::white); + + + QLinearGradient backgroundGradient; + backgroundGradient.setColorAt(0.0, Qt::white); + backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); + backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); + chartView->setChartBackgroundBrush(backgroundGradient); QChartAxis axis = chartView->defaultAxisX(); axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); axis.setGridPen(Qt::DashLine); chartView->setDefaultAxisX(axis); - axis.setShadesBrush(Qt::lightGray); + axis.setShadesBrush(Qt::yellow); chartView->setDefaultAxisY(axis); window.setCentralWidget(chartView); diff --git a/src/axisitem.cpp b/src/axisitem.cpp index 1531ab9..5b08c3d 100644 --- a/src/axisitem.cpp +++ b/src/axisitem.cpp @@ -95,6 +95,7 @@ void AxisItem::updateDomain() if(i%2){ QGraphicsRectItem *rectItem = static_cast(shades.at(i/2)); rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height()); + rectItem->setOpacity( 0.5 ); } } } @@ -125,6 +126,7 @@ void AxisItem::updateDomain() if(i%2){ QGraphicsRectItem *rectItem = static_cast(shades.at(i/2)); rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY); + } } } @@ -160,7 +162,7 @@ void AxisItem::handleAxisChanged(const QChartAxis& axis) } if(axis.isShadesVisible()) { - setShadesOpacity(100); + setShadesOpacity(axis.shadesOpacity()); } else { setShadesOpacity(0); diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 8c53977..cfe5bd3 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -240,6 +240,7 @@ void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) axis.setLabelsBrush(Qt::black); axis.setLabelsPen(Qt::NoPen); axis.setShadesPen(Qt::NoPen); + axis.setShadesOpacity(0.5); item->handleAxisChanged(axis); } diff --git a/src/qchartaxis.cpp b/src/qchartaxis.cpp index 2161e81..b5f18d3 100644 --- a/src/qchartaxis.cpp +++ b/src/qchartaxis.cpp @@ -6,7 +6,8 @@ QChartAxis::QChartAxis(): m_axisVisible(true), m_gridVisible(true), m_labelsVisible(true), -m_shadesVisible(true) +m_shadesVisible(true), +m_shadesOpacity(1.0) { // TODO Auto-generated constructor stub @@ -77,5 +78,9 @@ void QChartAxis::setShadesBrush(const QBrush& brush) m_shadesBrush=brush; } +void QChartAxis::setShadesOpacity(qreal opacity) +{ + m_shadesOpacity=opacity; +} QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartaxis.h b/src/qchartaxis.h index 0e899d0..557bf36 100644 --- a/src/qchartaxis.h +++ b/src/qchartaxis.h @@ -49,6 +49,9 @@ public: QPen shadesPen() const { return m_shadesPen;} void setShadesBrush(const QBrush& brush); QBrush shadesBrush() const { return m_shadesBrush;} + void setShadesOpacity(qreal opacity); + qreal shadesOpacity() const { return m_shadesOpacity;} + private: @@ -69,6 +72,9 @@ private: QPen m_shadesPen; QBrush m_shadesBrush; + qreal m_shadesOpacity; + + LabelsOrientation m_labelsOrientation; };