[vtkusers] QPixmap::grabWidget() doesn't work for QVTKWidget

Shekhar Shekhar.Chandra at sci.monash.edu.au
Fri Mar 7 08:23:46 EST 2008


Hi Manuel,

Thats normal as far as my experience goes. You will need to get VTK to
pull the OpenGL stuff out of the window. Use the vtkWindowToImageFilter
class like:

vtkWindowToImageFilter *windowToImage = vtkWindowToImageFilter::New();
QVTKWidget *windowVTK = qobject_cast<QVTKWidget *>(activeWindow);

///Capture Window
windowToImage->SetInput(windowVTK->GetRenderWindow());
windowToImage->Update();

///Write/Save as PNG
vtkPNGWriter *writer = vtkPNGWriter::New();
writer->SetInputConnection(windowToImage->GetOutputPort()); //Cant group
outside if's GCC compiler error
writer->SetFileName(filename.toStdString().c_str());
windowVTK->GetRenderWindow()->Render();
writer->Write();
writer->Delete();

Hope that helps.
Cheers Shakes.

Manuel Feige wrote:
> Hi All!
> I'm trying to make a screenshot of the QVTKWidget with
> QPixmap::grabWidget(). But this results in a gray picture. I've got
> the same
> problem in ParaView (3.0.2) when I save a screenshot as pdf file.
> I'm using VTK 5.0.3 with QT 4.3.3.
> Below you will find a simple test program.
>
> Regards,
> Manuel
>
> #include <QtGui>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkSphereSource.h>
> #include <QVTKWidget.h>
> #include "MainWindow.h"
> MainWindow::MainWindow()
> {
> testAction = new QAction(tr("&Test"), this);
> connect(testAction, SIGNAL(triggered()), this, SLOT(test()));
> testMenu = menuBar()->addMenu(tr("&Test"));
> testMenu->addAction(testAction);
> createMainWidget();
> showMaximized();
> }
> void MainWindow::createMainWidget()
> {
> mainWidget = new QVTKWidget(this);
> vtkSphereSource* sphere = vtkSphereSource::New();
> vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
> mapper->SetInput(sphere->GetOutput());
> vtkActor* actor = vtkActor::New();
> actor->SetMapper(mapper);
> vtkRenderer* ren = vtkRenderer::New();
> ren->AddActor(actor);
> mainWidget->GetRenderWindow()->AddRenderer(ren);
> setCentralWidget(mainWidget);
> }
> void MainWindow::test()
> {
> QPixmap pix = QPixmap::grabWidget(mainWidget);
> pix.save("C:/Test.bmp");
> }
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080308/c0ef79f1/attachment.htm>


More information about the vtkusers mailing list