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

}

}

实现效果如下所示:

相关推荐
qq_397562313 小时前
QT工程 , 生成别的电脑运行的exe程序
嵌入式硬件·qt
轩情吖3 小时前
Qt的窗口
开发语言·c++·qt·窗口·工具栏·桌面级开发
凯子坚持 c4 小时前
Qt常用控件指南(8)
开发语言·数据库·qt
深蓝海拓4 小时前
PySide6从0开始学习的笔记(二十六) 重写Qt窗口对象的事件(QEvent)处理方法
笔记·python·qt·学习·pyqt
深蓝海拓7 小时前
PySide6从0开始学习的笔记(二十五) Qt窗口对象的生命周期和及时销毁
笔记·python·qt·学习·pyqt
从此不归路10 小时前
Qt5 进阶【13】桌面 Qt 项目架构设计:从 MVC/MVVM 到模块划分
开发语言·c++·qt·架构·mvc
无小道12 小时前
QT——简介
qt
xmRao13 小时前
Qt+FFmpeg 实现音频重采样
qt·ffmpeg·音视频
专注echarts研发20年13 小时前
如何实现 QLabel 的 Click 事件?Qt 富文本超链接优雅方案
开发语言·qt
小小码农Come on13 小时前
QT控件之QTabWidget使用
开发语言·qt