[vtkusers] vtkRenderView subclasses in PyQt4 app?

Eric E. Monson emonson at cs.duke.edu
Fri May 21 15:49:47 EDT 2010


So, I finally got back to this and figured out the small change that makes it work. I'm just posting here in case someone else is trying to get the vtkRenderView subclasses to work in a PyQt4 app.

In the code I posted before, you just have to replace the commented-out self.view.SetInteractor() call with:

style = vtk.vtkInteractorStyleRubberBand2D()
self.view.SetInteractorStyle(style)

and it works fine after that. I have also gotten the charts to work by making an additional call after these two lines to:

self.view.SetInteractionModeTo2D()

where in the charts case self.view = vtk.vtkContextView()

Take care,
-Eric


On Mar 15, 2010, at 9:50 AM, Eric E. Monson wrote:

> Hello,
> 
> I am wondering if anyone has been able to use the QVTKRenderWindowInteractor in a Qt form using PyQt4 with any of the vtkRenderView children (graph view, icicle view, parallel coordinates view...)?
> 
> A long time ago I used to be able to build .ui forms in Qt Designer, then use them with PyQt4 to display a vtkGraphLayoutView along with other app widgets. Then, maybe a year ago there was some major refactoring of the vtkRenderView classes and I was getting an extra window popping up when I instantiated my vtkGraphLayoutView.
> 
> I was able to get rid of the extra window popping up (with Jeff Baumes' help) by feeding the RenderWindow from the graph layout view to the QVTKRenderWindowInteractor upon its construction, and I can view a graph and interact with it using the generic interactor, but none of the fancy selecting, coloring, etc, work like they should. 
> 
> Now I need to do a larger app with linked views (selections), and I'd rather use Python (because I'm gluing some other code together) and I'd rather not recreate all of the nice functionality of these render views in a standard render window (even if I could).
> 
> So, has anyone successfully used PyQt4 with a vtkRenderView subclass lately using the QVTKRenderWindowInteractor?
> 
> I'll attach the base code that shows a small graph in a panel of a Qt MainWindow. Uncommenting the self.view.SetInteractor() line doesn't seem to make any difference that I can see (I put it in since in C++ you have to do something like that with the QVTKWidget), and I can't seem to get the render window to behave like a vtkGraphLayoutView no matter what variations I try. 
> 
> If someone could help me figure out if it's possible to get this all to work, I'd really appreciate it!
> 
> Thanks,
> -Eric
> 
> ------------------------------------------------------
> Eric E Monson
> Duke Visualization Technology Group
> 
> # =================
> from PyQt4 import QtCore, QtGui
> from PyQt4.QtGui import QApplication
> import vtk
> from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
> import sys
> 
> class Ui_MainWindow(object):
>    def setupUi(self, MainWindow,renWin):
>        MainWindow.setObjectName("MainWindow")
>        MainWindow.resize(603, 553)
>        self.centralWidget = QtGui.QWidget(MainWindow)
>        self.gridlayout = QtGui.QGridLayout(self.centralWidget)
>        self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget, rw=renWin)
>        self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
>        MainWindow.setCentralWidget(self.centralWidget)
> 
> class SimpleView(QtGui.QMainWindow):
> 
>    def __init__(self, parent = None):
> 
>        QtGui.QMainWindow.__init__(self, parent)
>        self.ui = Ui_MainWindow()
> 
>        self.view = vtk.vtkGraphLayoutView()
>        self.ui.setupUi(self, self.view.GetRenderWindow())
>        # self.view.SetInteractor(self.ui.vtkWidget.GetRenderWindow().GetInteractor())
> 
>        subgraph = vtk.vtkRandomGraphSource()
>        self.view.SetRepresentationFromInputConnection(subgraph.GetOutputPort())
> 
>        self.view.ResetCamera()
>        self.view.GetInteractor().Start()
> 
> if __name__ == "__main__":
> 
>    app = QApplication(sys.argv)
>    window = SimpleView()
>    window.show()
>    sys.exit(app.exec_())
> 
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list