<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello,<br>
<div class="moz-forward-container"><br>
i am having problems using the VTK stuff in a QT QGraphicsview
project. I dont use any normal QT GUI classes, just the opengl
rendered stuff with QGraphicsView and QGraphicsScene. VTK has
created the QVTKGraphicsItem class for that reason, but it doesnt
work right:<br>
<br>
<img alt="ChartPicture.jpg"
src="cid:part1.03010105.08020908@whosme.de" height="341"
width="1146"><br>
<br>
The Chart will appear, but as soon as i click anywhere in the
chart (or using the mousewheel on top of the chart), the content
will disappear :( The contents wont come back, except when i
resize the QVTKGraphicsItem, then it repaints and the content is
there again. But i would like to get the events/interaction right,
so that i can zoom into the chart. Is this a bug?<br>
<br>
Here is somekind of the minimal code of the problem:<br>
<br>
<br>
#include "vtkSmartPointer.h"<br>
#include "QVTKGraphicsItem.h"<br>
#include "vtkChartXY.h"<br>
#include "vtkTable.h"<br>
#include "vtkFloatArray.h"<br>
#include "vtkPlot.h"<br>
#include "vtkRenderer.h"<br>
#include "vtkNew.h"<br>
#include "vtkGenericOpenGLRenderWindow.h"<br>
#include "vtkContextActor.h"<br>
#include "vtkContextScene.h"<br>
<br>
#include <qgraphicsscene><br>
#include <qgraphicsview><br>
#include <qapplication><br>
<br>
int main(int argc, char* argv[])<br>
{<br>
//First create QT QGraphicsview with QGraphicsScene<br>
//--------QT---------------<br>
QApplication a(argc, argv); <br>
QGraphicsView v;<br>
QGraphicsScene s;<br>
v.setScene(&s);<br>
QGLWidget glwidget(QGLFormat::defaultFormat());<br>
QGLContext context( QGLFormat::defaultFormat());<br>
glwidget.makeCurrent();<br>
v.setViewport(&glwidget);<br>
<br>
//Now create a chart with openglrenderer<br>
//---------vtk ------------<br>
<br>
QVTKGraphicsItem* item = new
QVTKGraphicsItem(&context); <br>
item->setGeometry(10,20,500,300);<br>
<br>
vtkNew<vtkChartXY> chart;<br>
vtkNew<vtkContextScene> chartScene;<br>
vtkNew<vtkContextActor> chartActor;<br>
<br>
chartScene->AddItem(chart.GetPointer());<br>
chartActor->SetScene(chartScene.GetPointer());<br>
<br>
vtkNew<vtkTable> table;<br>
vtkNew<vtkFloatArray> arrX;<br>
arrX->SetName("X");<br>
table->AddColumn(arrX.GetPointer());<br>
vtkNew<vtkFloatArray> arrV;<br>
<br>
arrV->SetName( "bla" );<br>
<br>
table->AddColumn(arrV.GetPointer()); <br>
<br>
auto numPoints = 5;<br>
table->SetNumberOfRows(numPoints);<br>
<br>
for (auto i = 0; i < numPoints; ++i)<br>
{<br>
table->SetValue(i, 0, i);<br>
table->SetValue(i, 1, i*2);<br>
}<br>
<br>
vtkPlot *points = chart->AddPlot(vtkChart::BAR);<br>
points->SetInput(table.GetPointer(), 0, 1);<br>
points->SetColor(140, 10, 200, 255);<br>
points->SetWidth(3.0);<br>
<br>
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();<br>
renderer->SetBackground(0.3, 0.3, 0.3);<br>
<br>
renderer->AddActor(chartActor.GetPointer());<br>
chartScene->SetRenderer(renderer.GetPointer());<br>
<br>
vtkSmartPointer<vtkGenericOpenGLRenderWindow>
renderWindow =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
<br>
renderWindow->AddRenderer( renderer );<br>
<br>
item->SetRenderWindow( renderWindow.GetPointer() );<br>
<br>
//now add the vtk item to the qgraphicsscene and show it:<br>
//----------QT-------<br>
s.addItem(item);<br>
<br>
v.show();<br>
a.exec();<br>
}<br>
<br>
Best regards,<br>
Matthias Thurau<br>
<br>
</div>
<br>
</body>
</html>