天天看點

Qt&Vtk-021-HelloWorld2 代碼搬運

Qt&Vtk-021-HelloWorld2 代碼搬運

現在才看到HelloWorld

文章目錄

1 官方示例展示

2 代碼搬運

2.1helloworld.h

2.2helloworld.cpp

3 運作效果

★ 源碼 ★

這HelloWorld跑這裡來了。這個應該是第一個出現的,跑這裡就跑這裡來吧。

Qt&Vtk-021-HelloWorld2 代碼搬運

#ifndef HELLOWORLD_H
#define HELLOWORLD_H

#include <QWidget>
#include "vtkGraphLayoutView.h"
#include "vtkRandomGraphSource.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
namespace Ui {
class HelloWorld;
}

class HelloWorld : public QWidget
{
    Q_OBJECT

public:
    explicit HelloWorld(QWidget *parent = 0);
    ~HelloWorld();

private:
    Ui::HelloWorld *ui;
};

#endif // HELLOWORLD_H

      

#include "helloworld.h"
#include "ui_helloworld.h"

HelloWorld::HelloWorld(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HelloWorld)
{
    ui->setupUi(this);

    vtkRandomGraphSource *source = vtkRandomGraphSource::New();

    vtkGraphLayoutView *view = vtkGraphLayoutView::New();
    view->SetRepresentationFromInputConnection(source->GetOutputPort());
    view->SetRenderWindow(ui->widget->GetRenderWindow());
    view->ResetCamera();
    view->Render();

}

HelloWorld::~HelloWorld()
{
    delete ui;
}

      
Qt&amp;Vtk-021-HelloWorld2 代碼搬運
Qt&amp;Vtk-021-HelloWorld2 代碼搬運

繼續閱讀