[vtkusers] How to put Qt widgets on top of a VTK OpenGL scene
Elvis Dowson
elvis.dowson at mac.com
Wed Oct 15 07:53:03 EDT 2008
Hi,
I did a little bit more digging around the sources and found
the following pieces of information.
Qt 4.4.3: QGLWidget Class Reference
QGLWidget provides functionality for displaying OpenGL graphics
integrated into a Qt application. It is very simple to use. You
inherit from it and use the subclass like any other QWidget, except
that you have the choice between using QPainter and standard OpenGL
rendering commands.
If you look at the QVTKWidget class, it inherits from QWidget and uses
the QPainter class to render images onto the window. Correct me if I'm
wrong, but if we replace this with standard OpenGL rendering commands,
we should be able to get a performance increase in rendering VTK when
using it with Qt.
void QVTKWidget::paintEvent(QPaintEvent* )
{
..
// In Qt 4.1+ let's support redirected painting
#if QT_VERSION >= 0x040100
// if redirected, let's grab the image from VTK, and paint it to
the device
QPaintDevice* device = QPainter::redirected(this);
if(device != NULL && device != this)
{
int w = this->width();
int h = this->height();
QImage img(w, h, QImage::Format_RGB32);
vtkUnsignedCharArray* pixels = vtkUnsignedCharArray::New();
pixels->SetArray(img.bits(), w*h*4, 1);
this->mRenWin->GetRGBACharPixelData(0, 0, w-1, h-1, 1, pixels);
pixels->Delete();
img = img.rgbSwapped();
img = img.mirrored();
QPainter painter(this);
painter.drawImage(QPointF(0.0,0.0), img);
return;
}
#endif
}
..
}
Best regards,
Elvis Dowson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081015/3cdb7a1f/attachment.htm>
More information about the vtkusers
mailing list