【问题标题】:How to choose from which side of QCPCurve fill with gradient?如何选择 QCPCurve 的哪一侧填充渐变?
【发布时间】:2018-01-21 10:10:47
【问题描述】:

我正在使用 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();

【问题讨论】:

    标签: c++ qt graph curve qcustomplot


    【解决方案1】:

    一种可能的解决方案是使用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找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2016-12-14
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多