繁体   English   中英

如何相对于X轴更改Qcustomplot中曲线颜色的强度?

[英]how to change the intensity of curve colour in Qcustomplot with respect to x-axis?

我有一个问题需要从某处绘制光线,在光源处强度应该是最强的,并且应该随着距离的减小而减小,这是我的x轴。如果我使用蓝色绘制光线,则其原点应该是浅蓝色并且应该随着距离变暗。

我已将QCpcurve附加到QCustomplot。

有两个向量必须说出X和Y

Curve.setpen(blue);
Curve.setdata(X,Y);

问题在于如何随着距离的增加而改变色彩强度。

请帮忙

您可以通过显示所需的外观为QPen设置颜色渐变。

QPen :: QPen(const QBrush&brush,qreal width,Qt :: PenStyle style = Qt :: SolidLine,Qt :: PenCapStyle cap = Qt :: SquareCap,Qt :: PenJoinStyle join = Qt :: BevelJoin)

使用指定的笔刷,宽度,笔样式,笔帽样式和连接样式构造一支笔。

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QCustomPlot *customplot = new QCustomPlot;
    customplot->setWindowTitle("Gradient Color");
    customplot->resize(640, 480);
    QCPCurve curve(customplot->xAxis, customplot->yAxis);
    QVector<double> x, y;
    for(int i=0; i < 1000; i++){
        double x_ = qDegreesToRadians(i*1.0);
        x << x_;
        y << qCos(x_)*qExp(-0.2*x_);
    }
    customplot->xAxis->setRange(0, qDegreesToRadians(1000.0));
    customplot->yAxis->setRange(-1, 1);

    QLinearGradient gradient(customplot->rect().topLeft(), customplot->rect().topRight());
    gradient.setColorAt(0.0, QColor::fromRgb(14, 11, 63));
    gradient.setColorAt(1.0, QColor::fromRgb(58, 98, 240));
    QPen pen(gradient, 5);
    curve.setPen(pen);

    curve.setData(x, y);
    customplot->show();

    return a.exec();
}

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM