QBrush 是画刷,可以用于设置填充图案的颜色。
QPen 是画笔,可以用于设置画笔的颜色。
在与QCustomplot结合的案例中,
void MainWindow::setupPlot()
{
// The following plot setup is mostly taken from the plot demos:
ui->plot->addGraph();
ui->plot->graph()->setPen(QPen(Qt::blue));
ui->plot->graph()->setBrush(QBrush(QColor(0, 0, 255, 20)));
ui->plot->addGraph();
ui->plot->graph()->setPen(QPen(Qt::red));
QVector<double> x(500), y0(500), y1(500);
for (int i=0; i<500; ++i)
{
x[i] = (i/499.0-0.5)*10;
y0[i] = qExp(-x[i]*x[i]*0.25)*qSin(x[i]*5)*5;
y1[i] = qExp(-x[i]*x[i]*0.25)*5;
}
ui->plot->graph(0)->setData(x, y0);
ui->plot->graph(1)->setData(x, y1);
ui->plot->axisRect()->setupFullAxesBox(true);
ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
}
运行结果如下,