gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:38:12 24 4
gpt4 key购买 nike

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

what i need to do

_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中找到

enter image description here

关于c++ - 如何选择从QCPCurve的哪一侧填充渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48365707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com