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

How to choose from which side of QCPCurve fill with gradient?

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

_myPlot->clearPlottables();

QVector<double> x;
QVector<double> y;

for(int point = 0; point < shadowZone.length() ; point++){
    x.push_back(shadowZone.at(point).longitude);
    y.push_back(shadowZone.at(point).latitude);
}

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

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

_myPlot->replot();

一个可能的解决方案是用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