0


QCustomplot常用设置

QCustomplot常用设置

QCustomplot常用设置

//设置图例图标大小
ui->customPlot->legend->setIconSize(0,0);
//设置图例文字颜色
ui->customPlot->legend->setTextColor(TextColor);//设置图例文字颜色
//设置图例是否可用
ui->customPlot->legend->setVisible(false); //设置图例是否可用
//在图例中添加线
ui->customPlot->axisRect()->setupFullAxesBox();
//将图例矩形域放到右上角
ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignTop|Qt::AlignRight);
//设置图例背景色
ui->customPlot->legend->setBrush(QColor(255,255,255,0));//设置背景色
// 设置图例行优先排列
plot->legend->setFillOrder(QCPLayoutGrid::foColumnsFirst);
// 设置六个图例自动换行
plot->legend->setWrap(6);
// 设置图例可见
plot->legend->setVisible(true);
// 设置图例位置,这里选择显示在QCPAxisRect下方,同理可设置显示在QCustomPlot中任意位置
plot->plotLayout()->addElement(1 , 0, plot->legend);
// 设置显示比例
plot->plotLayout()->setRowStretchFactor(1, 0.001);
// 设置边框隐藏
plot->legend->setBorderPen(Qt::NoPen);

// init customplot
ui->customPlot->xAxis->setLabel(“x”);
ui->customPlot->yAxis->setLabel(“y”);
ui->customPlot->axisRect()->setupFullAxesBox();//四边安装轴并显示

//设置字体
QFont font;
font.setPixelSize(25);//文字像素大小
font.setFamily(“微软雅黑”);//字体
ui->customPlot->legend->setFont(font);
ui->customPlot->legend->setBrush(QColor(100, 100, 100, 0));//设置图例背景颜色,可设置透明
//设置字体
QFont font1;
font1.setPixelSize(20);//文字像素大小
ui->customPlot->xAxis->setTickLabelFont(font1);
ui->customPlot->yAxis->setTickLabelFont(font1);
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
//设置颜色
pen.setColor(color);
ui->customPlot->graph(ui->customPlot->graphCount()-1)->setPen(pen);
ui->customPlot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ScatterShape::ssCircle,15));
ui->customPlot->graph(ui->customPlot->graphCount()-1)->setName(name);
QFont ft;
ft.setPointSize(22);
ui->customPlot->xAxis->setLabelFont(ft);
ui->customPlot->xAxis->setLabel(xaxis);

//隐藏所有图例和曲线
for (int i = 0; i < ui->customPlot->legend->elementCount(); ++i)
{
//takeAt(i)函数不会导致图例总数减少,只是让全局数组mElements[row][col]中那个图例位置指针为0,
//且那个图例未删除,只是未显示
if(ui->customPlot->legend->elementAt(i)){
ui->customPlot->legend->elementAt(i)->setVisible(false);
ui->customPlot->legend->takeAt(i);
}
}
for (int i = 0; i < ui->customPlot->graphCount(); ++i) {
ui->customPlot->graph(i)->setVisible(false);
}

//遍历出哪些图例和曲线需要显示
cntActualGraph = 0;
ui->labelNumLineActual->setText(QString::number(cntActualGraph));
for (int i = 0; i < numGraph; ++i) {
QCheckBox* cb = this->findChild<QCheckBox *>(“checkBox_”+QString::number(i+1));
if(cb->isChecked()){
ui->customPlot->graph(i)->setVisible(true);
ui->customPlot->legend->addElement(mapLegend[cb->text()]);
mapLegend[cb->text()]->setVisible(true);
ui->labelNumLineActual->setText(QString::number(++cntActualGraph));
}
}
ui->customPlot->legend->simplify(); //上面的take函数拿掉了某个图例,一定需要最后调用一下这个函数,使得无效图例不占用空间,仅仅包裹
ui->customPlot->replot();

标签: ui qt 开发语言

本文转载自: https://blog.csdn.net/shkis/article/details/129027308
版权归原作者 shkis 所有, 如有侵权,请联系我们删除。

“QCustomplot常用设置”的评论:

还没有评论