qcustomplot 显示坐标轴

(1)头文件

#pragma once

#include <QtWidgets/QMainWindow>

#include "ui_QCustomplotDemo1.h"

#include "qcustomplot.h"

class QCustomplotDemo1 : public QMainWindow

{

Q_OBJECT

public:

QCustomplotDemo1(QWidget *parent = nullptr);

~QCustomplotDemo1();

private:

Ui::QCustomplotDemo1Class ui;

QCustomPlot* m_pCurve;

void initGraph(void);

};

(2)实现文件

#include "QCustomplotDemo1.h"

QCustomplotDemo1::QCustomplotDemo1(QWidget *parent)

: QMainWindow(parent)

{

ui.setupUi(this);

m_pCurve = new QCustomPlot;

setCentralWidget(m_pCurve);

initGraph();

}

QCustomplotDemo1::~QCustomplotDemo1()

{}

void QCustomplotDemo1::initGraph(void)

{

//背景色

// m_pCurve->setBackground(QBrush(QColor(0, 0, 0)));

m_pCurve->xAxis->setLabel("X");//x轴名称

m_pCurve->yAxis->setLabel("Y");//y轴名称

m_pCurve->xAxis->setLabelColor(QColor(0, 0, 0));//坐标轴名称的颜色

m_pCurve->yAxis->setLabelColor(QColor(0, 0, 0));

//坐标轴刻度标注的颜色

m_pCurve->xAxis->setTickLabelColor(QColor(0, 0, 0));

m_pCurve->yAxis->setTickLabelColor(QColor(0, 0, 0));

//坐标轴的颜色

QPen pen1 = m_pCurve->xAxis->basePen();

pen1.setColor(QColor(0, 0, 0));

m_pCurve->xAxis->setTickPen(pen1);

m_pCurve->xAxis->setBasePen(pen1);

m_pCurve->xAxis->setSubTickPen(pen1);

QPen pen2 = m_pCurve->yAxis->basePen();

pen2.setColor(QColor(255, 255, 255));

m_pCurve->yAxis->setTickPen(pen2);

m_pCurve->yAxis->setBasePen(pen2);

m_pCurve->yAxis->setSubTickPen(pen2);

m_pCurve->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);

QCPGraph* pGraph = m_pCurve->addGraph();//返回值就是m_pCurve->graph(0)

if (pGraph)

{

pGraph->setPen(QPen(QColor(255, 0, 0)));

}

}

实现效果如下所示:

相关推荐
ae_zr18 小时前
QT动态编译应用后,如何快速获取依赖
开发语言·qt
LYOBOYI12319 小时前
qml的对象树机制
c++·qt
菜鸟小芯20 小时前
Qt Creator 集成开发环境下载安装
开发语言·qt
牵牛老人1 天前
Qt中集成 MQTT 来实现物联网通信:从原理到实战全解析
开发语言·qt·物联网
LYOBOYI1231 天前
qml的布局策略
c++·qt
小小码农Come on1 天前
QT常用控件:QListWidget
开发语言·qt
侯孟禹1 天前
Gemini写的抠图工具
qt·opencv
空空空空空空空空空空空空如也1 天前
QT通过编译宏区分x86 linux arm的方法
linux·开发语言·qt
四维碎片2 天前
【Qt】UDP跨平台调试工具
qt·学习·udp
踏过山河,踏过海2 天前
【用ui文件做个简单工具的开发,为什么修改完ui后,程序重新编译运行后,GUI界面还是不变呢?】
qt·ui