[vtkusers] QVTKOpenGLWidget usage with QtCreator

Elvis Stansvik elvis.stansvik at orexplore.com
Sat Aug 26 08:01:22 EDT 2017


Here is a minimal example that works here (VTK 8.0.0, Qt 5.5.1). The
result is as attached. I hope that helps.

If you're using the multiple inheritance approach (like I'm doing
here), perhaps you were forgetting to call setupUi?

Elvis


example.cpp:

#include "MainWindow.h"

#include <QApplication>
#include <QSurfaceFormat>

#include <QVTKOpenGLWidget.h>

int main(int argc, char *argv[]) {
  QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());

  QApplication app(argc, argv);

  MainWindow window;
  window.show();

  return app.exec();
}


MainWindow.h:

#pragma once

#include "ui_MainWindow.h"

class MainWindow : public QMainWindow, private Ui::MainWindow {
  Q_OBJECT

public:
  explicit MainWindow(QWidget *parent = 0);
};


MainWindow.cpp:

#include "MainWindow.h"

#include <QVTKOpenGLWidget.h>

#include <vtkCylinderSource.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
  setupUi(this);

  auto cylinderSource = vtkSmartPointer<vtkCylinderSource>::New();
  cylinderSource->SetCenter(0.0, 0.0, 0.0);
  cylinderSource->SetRadius(5.0);
  cylinderSource->SetHeight(7.0);
  cylinderSource->SetResolution(100);

  auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(cylinderSource->GetOutputPort());

  auto actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  auto renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);

  auto window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
  window->AddRenderer(renderer);

  widget->SetRenderWindow(window);
}


MainWindow.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>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QVTKOpenGLWidget" name="widget" native="true"/>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>19</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <customwidgets>
  <customwidget>
   <class>QVTKOpenGLWidget</class>
   <extends>QWidget</extends>
   <header>QVTKOpenGLWidget.h</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>


2017-08-26 11:12 GMT+02:00 Mads M. Hansen <madsmh at gmail.com>:
> I have been trying to use QVTKOpenGLWidget by promoting a QWiget in
> QtCreator, but that seems to result in in a segfault. I have tried
> searching for some documentation an found the class reference, but
> that does not seem to address QtCreator.
>
> Thanks in advance.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 10383 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170826/83102304/attachment.png>


More information about the vtkusers mailing list