QCustomPlot笔记——图例设置

///标题和图例设置

    ui->customplot_bar->plotLayout()->insertRow(0);

    QCPTextElement *title = new QCPTextElement(ui->customplot_bar, "bar", QFont("sans", 12, QFont::Bold));

    ui->customplot_bar->plotLayout()->addElement(0, 0, title);

    title->setTextColor(QColor(138,180,219));    //设置标题的颜色

 

    QCPBars *bars1 = new QCPBars(ui->customplot_bar->xAxis, ui->customplot_bar->yAxis);    

    bars1->setPen(QPen(QColor(138,180,219)));

    bars1->setName("RVP900");

    QCPBars *bars2 = new QCPBars(ui->customplot_bar->xAxis, ui->customplot_bar->yAxis);   

    bars2->setPen(QPen(QColor(138,180,219)));

    bars2->setName("敏视达");

//  ui->customplot_bar->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignCenter|Qt::AlignTop);  //图例居中显示

    ui->customplot_bar->legend->setVisible(true);

    ui->customplot_bar->legend->setFont(QFont("Helvetica", 8));

    ui->customplot_bar->legend->setTextColor(QColor(138,180,219));

    ui->customplot_bar->legend->setBrush(QBrush(Qt::transparent));     //设置图例透明无边框

    ui->customplot_bar->legend->setBorderPen(Qt::NoPen);

   //将图例设置成横排显示

    ui->customplot_bar->legend->addElement(0,1,ui->customplot_bar->legend->item(1));

    ui->customplot_bar->legend->addElement(0,2,ui->customplot_bar->legend->item(2));

图例置于底部

 ui->customplot_bar->legend->setMargins(QMargins(320,1,1,1));

    int count = ui->customplot_bar->plotLayout()->rowCount();

    ui->customplot_bar->plotLayout()->addElement(count,0, ui->customplot_bar->legend);

    ui->customplot_bar->plotLayout()->setRowStretchFactor(count, 0.0001);  //设置行的伸展因子

     ui->customplot_bar->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignTop);

 

 

参考文章:https://blog.csdn.net/chyuanrufeng/article/details/83056661

                  http://ebaina.com/u-big_anana/blog-1761.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值