我对 qcustomplot 和 qt 相当陌生(从 pyqt+matplotlib 切换以进行性能升级/学习)。我一直在研究 qcustomplot 的教程,但所有内容都围绕着绘制一个将 Qwidget 提升为 QCustomPlot 的 UI,这很好,但我猜如果我想要多个具有固定/可查看的 Qcustomplot / 子图,则需要手动绘制尺寸。到目前为止,我一直在尝试创建一个具有多轴的自定义图,以查看轴是否在滚动区域内改变大小,但到目前为止还没有运气。任何帮助,将不胜感激。
头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
cpp如下:
#include "ui_mainwindow.h"
#include "qcustomplot.h"
#include <QWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget plotWidget;
QVBoxLayout layout;
QCustomPlot customPlot;
for(int i = 0; i < 10; i++)
{
customPlot.plotLayout()->insertRow(i);
QCPAxisRect *ar = new QCPAxisRect(&customPlot);
customPlot.plotLayout()->addElement(i, 0, ar);
}
/*
layout.addWidget(customPLot);
plotWidget.setLayout(layout);
*/
ui->plotArea_SA->setWidget(customPlot);
}
MainWindow::~MainWindow()
{
delete ui;
}
和用户界面
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1269</width>
<height>454</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QScrollArea" name="plotArea_SA">
<property name="geometry">
<rect>
<x>169</x>
<y>9</y>
<width>1091</width>
<height>381</height>
</rect>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1089</width>
<height>379</height>
</rect>
</property>
</widget>
</widget>
<widget class="QScrollArea" name="searchTable_SA">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>161</width>
<height>151</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>159</width>
<height>149</height>
</rect>
</property>
</widget>
</widget>
<widget class="QScrollArea" name="displayTable_SA">
<property name="geometry">
<rect>
<x>0</x>
<y>170</y>
<width>161</width>
<height>221</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>159</width>
<height>219</height>
</rect>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1269</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>