[vtkusers] use QVTKWidget

David Doria daviddoria at gmail.com
Tue May 15 16:16:59 EDT 2012


On Tue, May 15, 2012 at 4:11 PM, Massi <Massinissa.Bandou at usherbrooke.ca> wrote:
> Hi
> I'm new on Qt and I want to display a JPEG image on my Qt interface. I know
> I have to use QVTKWidget but I have no idea how it works? Here is a basic
> code for reading a jpeg:
>
> #include "CoregistrationForm.h"
>
> int main(int argc, char *argv[])
> {
>      QApplication app(argc, argv);
>      vtkJPEGReader *jpegReader = vtkJPEGReader::New();
>
> jpegReader->SetFileName("/Users/Massi/Desktop/bin_myProject/Release/test.jpg");
>      jpegReader->Update();
>
>      vtkImageMapper *imageMapper =vtkImageMapper::New();
>      imageMapper->SetInput(jpegReader->GetOutput());
>      imageMapper->GetInput();
>
>      vtkImageActor *mapActor= vtkImageActor::New();
>      mapActor->SetInput(imageMapper->GetInput());
>      vtkRenderer *ren=vtkRenderer::New();
>      ren->AddActor(mapActor);
>      ren->ResetCamera();
>      ren->GetRenderWindow()->Render();
>
>      QVTKWidget *vtkWidget;
>      .....
>      ....????
>
> }
>
> my CoregistrationForm.h contains
>
> class CoregistrationForm : public QDialog {
>    Q_OBJECT
> public:
>    CoregistrationForm();
>    virtual ~CoregistrationForm();
> public slots:
>
> public:
>    Ui::CoregistrationForm widget;
> };
>
> Massi

There is nothing special about displaying an image - the QVTKWidget
just gives you a VTK render window inside of a Qt widget. Take a look
at this example:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowUIMultipleInheritance

Once you setup the QVTKWidget's render, you just do whatever you want
to do (e.g. display an image) just as you normally would with VTK, but
the renderer/renderWindow are now inside Qt rather than in a separate
window.

David



More information about the vtkusers mailing list