[vtkusers] vtkRenderView subclasses in PyQt4 app?
Eric E. Monson
emonson at cs.duke.edu
Mon Mar 15 09:50:14 EDT 2010
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_())
More information about the vtkusers
mailing list