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

}

}

实现效果如下所示:

相关推荐
范特西.i3 天前
QT聊天项目(8)
开发语言·qt
枫叶丹43 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
十五年专注C++开发3 天前
Qt deleteLater作用及源码分析
开发语言·c++·qt·qobject
kangzerun3 天前
SQLiteManager:一个优雅的Qt SQLite数据库操作类
数据库·qt·sqlite
金刚狼883 天前
qt和qt creator的下载安装
开发语言·qt
追烽少年x3 天前
Qt中使用Zint库显示二维码
qt
谁刺我心3 天前
qt源码、qt在线安装器镜像下载
开发语言·qt
金刚狼883 天前
在qt creator中创建helloworld程序并构建
开发语言·qt
扶尔魔ocy4 天前
【转载】QT使用linuxdeployqt打包
开发语言·qt
YxVoyager4 天前
在VS2017中使用Qt的foreach宏,IntelliSense无法正确识别函数定义
c++·qt