QT技巧系列(3)QCustomPlot各部分颜色设置代码

                                  QT技巧系列(3)QCustomPlot各部分颜色设置代码

 

        QCustomPlot 是一个基于Qt的画图和数据可视化C++控件。QCustomPlot 致力于提供美观的界面,高质量的2D画图、图画和图表,同时为实时数据可视化应用提供良好的解决方案。当QCustomPlot显示在有背景的窗体时,需要修改默认的一些颜色设置,不然有些地方显示不出来。下图如果窗体背景变为黑色,则坐标轴和文字就显示不出来。

通过设置不同部分的颜色来达到完美显示效果。

示例代码如下:

    //2019-8-5如果整个界面要用背景的话,这个图形显示需要设置显示背景

    ui->customPlot->setBackground(QBrush(Qt::black));

 

    //设置坐标文本颜色   

    ui->customPlot->xAxis->setTickLabelColor(Qt::white);

    ui->customPlot->yAxis->setTickLabelColor(Qt::white);

    //设置坐标名称文本颜色

    ui->customPlot->xAxis->setLabelColor(Qt::white);

    ui->customPlot->yAxis->setLabelColor(Qt::white);

    //设置坐标轴颜色

    ui->customPlot->xAxis->setBasePen(QPen(Qt::white));

    ui->customPlot->xAxis->setTickPen(QPen(Qt::white));

    ui->customPlot->xAxis->setSubTickPen(QPen(Qt::white));

   //设置label字体

   QFont xFont = ui->customPlot ->xAxis->labelFont();

   xFont.setPixelSize(20);

   ui->customPlot ->xAxis->setLabelFont(xFont);

 

    ui->customPlot->yAxis->setBasePen(QPen(Qt::white));

    ui->customPlot->yAxis->setTickPen(QPen(Qt::white));

    ui->customPlot->yAxis->setSubTickPen(QPen(Qt::white));

 

    //设置坐标轴名称

    ui->customPlot->xAxis->setLabel("时间轴");

    ui->customPlot->yAxis->setLabel("温度(℃)");

 

设置后显示效果如下图:

 

 

 

注:实战示例,解疑答惑。

           --不间端地思考,实时地批判你的工作!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值