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-018-FixedPointVolumeRayCastMapperCT
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
156 0
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
Qt&Vtk-024-PiecewiseItem
Qt&Vtk-024-PiecewiseItem
167 0
Qt&Vtk-024-PiecewiseItem
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-026-QScalarsToColors
213 0
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-008-Cone3
Qt&Vtk-008-Cone3
134 0
Qt&Vtk-008-Cone3
Qt&Vtk-010-Cone5
Qt&Vtk-010-Cone5
169 0
Qt&Vtk-010-Cone5
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-019-GPURenderDemo
160 0
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-016-DiffuseSpheres
129 0
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-022-LabeledMesh
Qt&Vtk-022-LabeledMesh
162 0
Qt&Vtk-022-LabeledMesh
Qt&Vtk-014-CustomLinkView
Qt&Vtk-014-CustomLinkView
143 0
Qt&Vtk-014-CustomLinkView
Qt&Vtk-011-Cone6
Qt&Vtk-011-Cone6
153 0
Qt&Vtk-011-Cone6