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

}

}

实现效果如下所示:

相关推荐
mengzhi啊1 天前
Qt Designer UI 界面 拖的两个 QLineEdit,想按 Tab 从第一个跳到第二个
qt
笨笨马甲1 天前
Qt MQTT
开发语言·qt
姓刘的哦1 天前
Qt实现蚂蚁线
开发语言·qt
Ivy_belief1 天前
Qt网络编程实战:从零掌握 QUdpSocket 及 UDP 通信
网络·qt·udp
丁劲犇1 天前
在Trae Solo模式下用Qt HttpServer和Concurrent升级MCP服务器绘制6G互联网覆盖区域
服务器·开发语言·qt·ai·6g·mcp·trae
笨笨马甲1 天前
Qt MODBUS协议
开发语言·qt
我喜欢就喜欢1 天前
Word 模板匹配与样式同步技术详解
开发语言·c++·qt·word·模板匹配
Ronin3051 天前
【Qt常用控件】容器类控件和布局管理器
开发语言·qt·常用控件·布局管理器·容器类控件
2301_803554522 天前
qt信号槽机制以及底层实现原理
开发语言·qt
笨笨马甲2 天前
Qt 音视频编解码
开发语言·qt