Qt&Vtk-025-QChartTable

简介: Qt&Vtk-025-QChartTable

image.png 摘要

文章目录


1 官方示例展示


今天接着人搬运代码,官方实例QChartTable,官方演示效果image.png

#ifndef QCHARTTABLE_H
#define QCHARTTABLE_H
#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkChartXY.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPlot.h"
#include "vtkQtTableView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include "vtkTimerLog.h"
#include "QHBoxLayout"
#include "QSurfaceFormat"
#include "QResizeEvent"
namespace Ui {
class QChartTable;
}
class QChartTable : public QWidget
{
    Q_OBJECT
public:
    explicit QChartTable(QWidget *parent = 0);
    ~QChartTable();
    void resizeEvent(QResizeEvent *event);
private:
    Ui::QChartTable *ui;
    QVTKOpenGLWidget *qvtkWidget = nullptr;
    vtkNew<vtkGenericOpenGLRenderWindow> renderWidow;
    vtkNew<vtkContextView> view;
    vtkNew<vtkTable> table;
    vtkNew<vtkFloatArray> arrX;
    vtkNew<vtkFloatArray> arrC;
    vtkNew<vtkFloatArray> arrS;
    vtkNew<vtkTimerLog> timers;
    vtkNew<vtkChartXY> chart;
    vtkNew<vtkQtTableView> tableview;
};
#endif // QCHARTTABLE_H

2.2 qcharttable.cpp


#include "qcharttable.h"
#include "ui_qcharttable.h"
QChartTable::QChartTable(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::QChartTable)
{
    ui->setupUi(this);
    qvtkWidget = new QVTKOpenGLWidget(ui->widget);
    qvtkWidget->SetRenderWindow(renderWidow);
    view->SetRenderWindow(renderWidow);
    view->SetInteractor(renderWidow->GetInteractor());
    arrX->SetName("X Axis");
    table->AddColumn(arrX);
    arrC->SetName("Cosine");
    table->AddColumn(arrC);
    arrS->SetName("Sine");
    table->AddColumn(arrS);
    int numPoints = 29;
    float inc = 7.0 / (numPoints - 1);
    table->SetNumberOfRows(numPoints);
    for(auto i = 0;i< numPoints;i++)
    {
        table->SetValue(i,0,i * inc);
        table->SetValue(i,1,cos(i * inc)+0.0);
        table->SetValue(i,2,sin(i * inc)+0.0);
    }
    view->GetScene()->AddItem(chart);
    vtkPlot *line = chart->AddPlot(vtkChart::LINE);
    line->SetInputData(table,0,1);
    line->SetColor(255,0,255);
    line = chart->AddPlot(vtkChart::LINE);
    line->SetInputData(table,0,2);
    line->SetColor(0,255,255);
    line->SetWidth(2.0);
    tableview->SetSplitMultiComponentColumns(true);
    tableview->AddRepresentationFromInput(table);
    tableview->Update();
    QHBoxLayout *layout = new QHBoxLayout(ui->widget);
    layout->addWidget(qvtkWidget, 2);
    layout->addWidget(tableview->GetWidget());
}
QChartTable::~QChartTable()
{
    delete ui;
}
void QChartTable::resizeEvent(QResizeEvent *event)
{
//    qvtkWidget->resize(ui->widget->size());
}

image.pngimage.pngimage.png

目录
相关文章
Qt&Vtk-008-Cone3
Qt&Vtk-008-Cone3
135 0
Qt&Vtk-008-Cone3
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-026-QScalarsToColors
215 0
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-019-GPURenderDemo
164 0
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-027-RGrid
Qt&Vtk-027-RGrid
158 0
Qt&Vtk-027-RGrid
Qt&Vtk-022-LabeledMesh
Qt&Vtk-022-LabeledMesh
165 0
Qt&Vtk-022-LabeledMesh
Qt&Vtk-009-Cone4
Qt&Vtk-009-Cone4
124 0
Qt&Vtk-009-Cone4
Qt&Vtk-017-EasyView
Qt&Vtk-017-EasyView
198 0
Qt&Vtk-017-EasyView
Qt&Vtk-011-Cone6
Qt&Vtk-011-Cone6
160 0
Qt&Vtk-011-Cone6
Qt&Vtk-028-SGrid
Qt&Vtk-028-SGrid
164 0
Qt&Vtk-028-SGrid
Qt&Vtk-006-one
Qt&Vtk-006-one
126 0
Qt&Vtk-006-one