VTK/Examples/Cxx/Qt/RenderWindowUIMultipleInheritance

From KitwarePublic

Jump to: navigation, search

Contents

RenderWindowUIMultipleInheritance.cxx

#include <QApplication>
#include "SimpleViewUI.h"
 
int main(int argc, char** argv)
{
  QApplication app(argc, argv);
 
  SimpleView mySimpleView;
  mySimpleView.show();
 
  return app.exec();
}

SimpleViewUI.h

#ifndef SimpleView_H
#define SimpleView_H
 
#include "ui_SimpleViewUI.h"
 
#include <QMainWindow>
 
class SimpleView : public QMainWindow, private Ui::SimpleView
{
  Q_OBJECT
public:
 
  SimpleView();
 
public slots:
 
  virtual void slotExit();
 
};
 
#endif

SimpleViewUI.cxx

#include "SimpleViewUI.h"
 
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
#include "vtkSmartPointer.h"
 
// Constructor
SimpleView::SimpleView()
{
  this->setupUi(this);
 
  // Sphere
  vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();
  vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
  vtkSmartPointer<vtkActor> sphereActor =
    vtkSmartPointer<vtkActor>::New();
  sphereActor->SetMapper(sphereMapper);
 
  // VTK Renderer
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(sphereActor);
 
  // VTK/Qt wedded
  this->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
 
  // Set up action signals and slots
  connect(this->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));
 
};
 
void SimpleView::slotExit()
{
  qApp->exit();
}

SimpleViewUI.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>SimpleView</class>
 <widget class="QMainWindow" name="SimpleView">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>541</width>
    <height>583</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>SimpleView</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QVTKWidget" name="qvtkWidget">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>20</y>
      <width>511</width>
      <height>541</height>
     </rect>
    </property>
   </widget>
  </widget>
  <action name="actionOpenFile">
   <property name="enabled">
    <bool>true</bool>
   </property>
   <property name="text">
    <string>Open File...</string>
   </property>
  </action>
  <action name="actionExit">
   <property name="text">
    <string>Exit</string>
   </property>
  </action>
  <action name="actionPrint">
   <property name="text">
    <string>Print</string>
   </property>
  </action>
  <action name="actionHelp">
   <property name="text">
    <string>Help</string>
   </property>
  </action>
  <action name="actionSave">
   <property name="text">
    <string>Save</string>
   </property>
  </action>
 </widget>
 <customwidgets>
  <customwidget>
   <class>QVTKWidget</class>
   <extends>QWidget</extends>
   <header>QVTKWidget.h</header>
  </customwidget>
 </customwidgets>
 <resources>
 
 </resources>
 <connections/>
</ui>

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(RenderWindowUIMultipleInheritance)
 
FIND_PACKAGE(VTK)
INCLUDE(${VTK_USE_FILE}) # include UseVTK.cmake
 
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})  # include UseQt4.cmake
 
# support for out-of-source build
INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR} #this is where ui_SimpleViewUI.h is generated
  ${CMAKE_CURRENT_SOURCE_DIR}
)
 
# Set your files and resources here
SET(SimpleViewSrcs RenderWindowUIMultipleInheritance.cxx SimpleViewUI.cxx)
SET(SimpleViewUI SimpleViewUI.ui)
SET(SimpleViewHeaders SimpleViewUI.h)
 
QT4_WRAP_UI(UISrcs ${SimpleViewUI})
QT4_WRAP_CPP(MOCSrcs ${SimpleViewHeaders} )
 
SOURCE_GROUP("Resources" FILES
  ${SimpleViewUI}
)
 
SOURCE_GROUP("Generated" FILES
  ${UISrcs}
  ${MOCSrcs}
)
 
ADD_EXECUTABLE( RenderWindowUIMultipleInheritance ${SimpleViewSrcs} ${UISrcs} ${MOCSrcs})
TARGET_LINK_LIBRARIES( RenderWindowUIMultipleInheritance QVTK )
Personal tools