答案 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
中找到完整的示例