摘要
1 官方示例展示
接着搬运,搬运到后面真的不是不想在手撸了,开启Ctrl+C Ctrl+V的节奏,官方示例演示如下
#ifndef THEME_H #define THEME_H #include <QWidget> #include "vtkGraphLayoutView.h" #include "vtkRandomGraphSource.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkViewTheme.h" namespace Ui { class Theme; } class Theme : public QWidget { Q_OBJECT public: explicit Theme(QWidget *parent = 0); ~Theme(); private: Ui::Theme *ui; vtkRandomGraphSource* source = nullptr; vtkGraphLayoutView* view = nullptr; vtkViewTheme* theme = nullptr; }; #endif // THEME_H
2.2 theme.cpp
#include "theme.h" #include "ui_theme.h" Theme::Theme(QWidget *parent) : QWidget(parent), ui(new Ui::Theme) { ui->setupUi(this); source = vtkRandomGraphSource::New(); view = vtkGraphLayoutView::New(); view->SetRepresentationFromInputConnection(source->GetOutputPort()); theme = vtkViewTheme::CreateMellowTheme(); view->ApplyViewTheme(theme); theme->Delete(); view->SetRenderWindow(ui->widget->GetRenderWindow()); view->SetVertexColorArrayName("VertexDegree"); view->SetColorVertices(true); view->SetVertexLabelArrayName("VertexDegree"); view->SetVertexLabelVisibility(true); view->ResetCamera(); view->Render(); } Theme::~Theme() { delete ui; }