[vtkusers] QVTKGraphicsItem Events / Unexpected Behavior
Matthias Thurau
thurau at whosme.de
Fri Jan 11 06:44:38 EST 2013
Hello,
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:
ChartPicture.jpg
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?
Here is somekind of the minimal code of the problem:
#include "vtkSmartPointer.h"
#include "QVTKGraphicsItem.h"
#include "vtkChartXY.h"
#include "vtkTable.h"
#include "vtkFloatArray.h"
#include "vtkPlot.h"
#include "vtkRenderer.h"
#include "vtkNew.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkContextActor.h"
#include "vtkContextScene.h"
#include <qgraphicsscene>
#include <qgraphicsview>
#include <qapplication>
int main(int argc, char* argv[])
{
//First create QT QGraphicsview with QGraphicsScene
//--------QT---------------
QApplication a(argc, argv);
QGraphicsView v;
QGraphicsScene s;
v.setScene(&s);
QGLWidget glwidget(QGLFormat::defaultFormat());
QGLContext context( QGLFormat::defaultFormat());
glwidget.makeCurrent();
v.setViewport(&glwidget);
//Now create a chart with openglrenderer
//---------vtk ------------
QVTKGraphicsItem* item = new QVTKGraphicsItem(&context);
item->setGeometry(10,20,500,300);
vtkNew<vtkChartXY> chart;
vtkNew<vtkContextScene> chartScene;
vtkNew<vtkContextActor> chartActor;
chartScene->AddItem(chart.GetPointer());
chartActor->SetScene(chartScene.GetPointer());
vtkNew<vtkTable> table;
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X");
table->AddColumn(arrX.GetPointer());
vtkNew<vtkFloatArray> arrV;
arrV->SetName( "bla" );
table->AddColumn(arrV.GetPointer());
auto numPoints = 5;
table->SetNumberOfRows(numPoints);
for (auto i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i);
table->SetValue(i, 1, i*2);
}
vtkPlot *points = chart->AddPlot(vtkChart::BAR);
points->SetInput(table.GetPointer(), 0, 1);
points->SetColor(140, 10, 200, 255);
points->SetWidth(3.0);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(0.3, 0.3, 0.3);
renderer->AddActor(chartActor.GetPointer());
chartScene->SetRenderer(renderer.GetPointer());
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renderWindow->AddRenderer( renderer );
item->SetRenderWindow( renderWindow.GetPointer() );
//now add the vtk item to the qgraphicsscene and show it:
//----------QT-------
s.addItem(item);
v.show();
a.exec();
}
Best regards,
Matthias Thurau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130111/8695c1db/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 54828 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130111/8695c1db/attachment.jpeg>
More information about the vtkusers
mailing list