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();

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值