[vtkusers] QPixmap::grabWidget() doesn't work for QVTKWidget
Alexey PETROV
alexey.petrov at opencascade.com
Fri Mar 7 09:22:40 EST 2008
Shekhar wrote:
> 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:
No !!!
If you completely do not take care of performance and complexity, then
let it be.
But there is a more elegant, straightforward and clear solution -
vtkRenderWindow* aWindow = anInteractor->getRenderWindow();
unsigned char *aData = aWindow->GetRGBACharPixelData( 0,
0,
theHorizontalWindowDimension - 1,
theVerticalWindowDimension - 1,
0 );
QImage anImage( aData,
theHorizontalDimension,
theVerticalDimension,
QImage::Format_ARGB32 );
// OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB
anImage = anImage.rgbSwapped();
anImage = anImage.mirrored();
But surely, it will be much better if someone will show us a way, when
it could be done automatically through overriding of some QWidget
methods ...
> 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
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/20080307/3303731e/attachment.htm>
More information about the vtkusers
mailing list