VTK/Examples/Cxx/Qt/BorderWidget
From KitwarePublic
Contents |
QtBorderWidget.cxx
#include <QApplication> #include "SimpleView.h" int main(int argc, char* argv[]) { QApplication app( argc, argv ); SimpleView mySimpleView; mySimpleView.show(); return app.exec(); }
SimpleView.cxx
#include "ui_SimpleView.h" #include "SimpleView.h" #include <vtkSmartPointer.h> #include <vtkBorderWidget.h> #include <vtkPolyDataMapper.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkSphereSource.h> class BorderCallback : public vtkCommand { public: BorderCallback(){} static BorderCallback *New() { return new BorderCallback; } virtual void Execute(vtkObject *caller, unsigned long, void*) { vtkBorderWidget *borderWidget = reinterpret_cast<vtkBorderWidget*>(caller); } }; // Constructor SimpleView::SimpleView() { this->ui = new Ui_SimpleView; this->ui->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); // Connect VTK with Qt this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer); // Add a border widget to the right renderer this->BorderWidget = vtkSmartPointer<vtkBorderWidget>::New(); this->BorderWidget->SetInteractor(this->ui->qvtkWidget->GetInteractor()); this->BorderWidget->On(); };
SimpleView.h
#ifndef SimpleView_H #define SimpleView_H #include <vtkSmartPointer.h> #include <QMainWindow> class vtkBorderWidget; // Forward Qt class declarations class Ui_SimpleView; class SimpleView : public QMainWindow { Q_OBJECT public: // Constructor/Destructor SimpleView(); ~SimpleView() {} private: Ui_SimpleView *ui; vtkSmartPointer<vtkBorderWidget> BorderWidget; }; #endif // SimpleView_H
SimpleView.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>572</width>
<height>583</height>
</rect>
</property>
<property name="windowTitle">
<string>SimpleView</string>
</property>
<property name="windowIcon">
<iconset resource="Icons/icons.qrc">
<normaloff>:/Icons/help.png</normaloff>:/Icons/help.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QVTKWidget" name="qvtkWidget" native="true">
<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="icon">
<iconset resource="Icons/icons.qrc">
<normaloff>:/Icons/fileopen.png</normaloff>:/Icons/fileopen.png</iconset>
</property>
<property name="text">
<string>Open File...</string>
</property>
</action>
<action name="actionExit">
<property name="icon">
<iconset>
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Exit</string>
</property>
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="Icons/icons.qrc">
<normaloff>:/Icons/print.png</normaloff>:/Icons/print.png</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
</action>
<action name="actionHelp">
<property name="icon">
<iconset resource="Icons/icons.qrc">
<normaloff>:/Icons/help.png</normaloff>:/Icons/help.png</iconset>
</property>
<property name="text">
<string>Help</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="Icons/icons.qrc">
<normaloff>:/Icons/filesave.png</normaloff>:/Icons/filesave.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QVTKWidget</class>
<extends>QWidget</extends>
<header>QVTKWidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Icons/icons.qrc"/>
</resources>
<connections/>
</ui>CMakeLists.txt
PROJECT(QtBorderWidget) FIND_PACKAGE(VTK) INCLUDE(${VTK_USE_FILE}) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) SET(SimpleViewSrcs QtBorderWidget.cxx SimpleView.cxx) SET(SimpleViewUI SimpleView.ui) SET(SimpleViewHeaders SimpleView.h) QT4_WRAP_UI(UISrcs ${SimpleViewUI}) QT4_WRAP_CPP(MOCSrcs ${SimpleViewHeaders} ) ADD_EXECUTABLE( QtBorderWidget ${SimpleViewSrcs} ${UISrcs} ${MOCSrcs}) TARGET_LINK_LIBRARIES( QtBorderWidget QVTK )