如何选择QCPCurve哪一侧填充渐变?

时间:2018-01-21 10:10:48

标签: c++ qt graph curve qcustomplot

我正在使用qcustomplot并绘制一条曲线(QCPCurve)。以下代码仅填充曲线上方的区域。但我想填补曲线另一侧的区域。如何使渐变填充区域直到图形的边界?

what i need to do

client1.webapp.com

1 个答案:

答案 0 :(得分:2)

一种可能的解决方案是使用QCPGraph而不是使用QCPCurve来使用setChannelFillGraph(),策略是创建另一个QCPGraph,它是图表的最低行,必要时,必须使用轴的rangeChanged信号更新图形。

QCPGraph *newCurve = new QCPGraph(_myPlot->xAxis , _myPlot->yAxis);
newCurve->addData(x,y);

QBrush shadowBrush(QColor(0,0,0), Qt::Dense7Pattern);

newCurve->setBrush(shadowBrush);

QCPGraph *minGraph = new QCPGraph(_myPlot->xAxis , _myPlot->yAxis);
newCurve->setChannelFillGraph(minGraph);

QObject::connect(_myPlot->xAxis, static_cast<void(QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), [_myPlot, minGraph](const QCPRange & newRange){
    minGraph->setData(QVector<double>{newRange.lower, newRange.upper},
                      QVector<double>{_myPlot->yAxis->range().lower,_myPlot->yAxis->range().lower});
});

QObject::connect(_myPlot->yAxis, static_cast<void(QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), [_myPlot, minGraph](const QCPRange & newRange){
    minGraph->setData(QVector<double>{_myPlot->xAxis->range().lower,_myPlot->xAxis->range().upper},
                      QVector<double>{newRange.lower, newRange.lower});
});

可以在以下link

中找到完整的示例

enter image description here