[vtkusers] Python Qt4 Vtk (5.8/5.10.1) Ubuntu 12.04
Niels Linnemann
ne.linnemann at gmail.com
Sun Jan 6 13:06:23 EST 2013
Hello
I found a Solution to the problem.
After the window.show() to start the qt Gui we need to initialize the
vtkWidget.
I found out about this by having a button that connected to a function that
only did self.widget.Initialize().
So Initializing the widget wont work if the QtGui havent started yet (sorta
makes sense).
The tutorials on this although have to be updated to reflect this.
Hope this helps some other poor souls in the same situation.
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
class Ui_MainWindow(QWidget):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(603, 553)
self.centralWidget = QWidget(MainWindow)
self.gridlayout = QGridLayout(self.centralWidget)
self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralWidget)
class SimpleView(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.widget = self.ui.vtkWidget
self.ren = vtk.vtkRenderer()
renwin = self.widget.GetRenderWindow()
renwin.AddRenderer(self.ren)
iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
cube = vtk.vtkCubeSource()
cube.SetXLength(200)
cube.SetYLength(200)
cube.SetZLength(200)
cube.Update()
cm = vtk.vtkPolyDataMapper()
cm.SetInputConnection(cube.GetOutputPort())
ca = vtk.vtkActor()
ca.SetMapper(cm)
self.ren.AddActor(ca)
self.axesActor = vtk.vtkAnnotatedCubeActor();
self.axesActor.SetXPlusFaceText('R')
self.axesActor.SetXMinusFaceText('L')
self.axesActor.SetYMinusFaceText('H')
self.axesActor.SetYPlusFaceText('F')
self.axesActor.SetZMinusFaceText('P')
self.axesActor.SetZPlusFaceText('A')
self.axesActor.GetTextEdgesProperty().SetColor(1,1,0)
self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
self.axesActor.GetCubeProperty().SetColor(0,0,1)
self.axes = vtk.vtkOrientationMarkerWidget()
self.axes.SetOrientationMarker(self.axesActor)
self.axes.SetInteractor(iren)
self.axes.EnabledOn()
self.axes.InteractiveOn()
self.ren.ResetCamera()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = SimpleView()
window.show()
window.widget.Initialize() #This is the line we need
app.exec_()
On Sat, Jan 5, 2013 at 8:43 PM, <lindeval at dmat.ufrr.br> wrote:
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> import vtk
> #from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
> import sys
> class Ui_MainWindow(QWidget):
> def setupUi(self, MainWindow):
> MainWindow.setObjectName("MainWindow")
> MainWindow.resize(603, 553)
> self.centralWidget = QWidget(MainWindow)
> self.vtkWidget = vtk.QVTKWidget(self.centralWidget)
> self.gridlayout = QGridLayout(self.centralWidget)
> #self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
> self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
> MainWindow.setCentralWidget(self.centralWidget)
>
> class SimpleView(QMainWindow):
> def __init__(self, parent = None):
> QMainWindow.__init__(self, parent)
> self.ui = Ui_MainWindow()
> self.ui.setupUi(self)
> widget = self.ui.vtkWidget
> self.ren = vtk.vtkRenderer()
> renwin = widget.GetRenderWindow()
> renwin.AddRenderer(self.ren)
> iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
> cube = vtk.vtkCubeSource()
> cube.SetXLength(200)
> cube.SetYLength(200)
> cube.SetZLength(200)
> cube.Update()
> cm = vtk.vtkPolyDataMapper()
> cm.SetInputConnection(cube.GetOutputPort())
> ca = vtk.vtkActor()
> ca.SetMapper(cm)
> self.ren.AddActor(ca)
> self.axesActor = vtk.vtkAnnotatedCubeActor();
> self.axesActor.SetXPlusFaceText('R')
> self.axesActor.SetXMinusFaceText('L')
> self.axesActor.SetYMinusFaceText('H')
> self.axesActor.SetYPlusFaceText('F')
> self.axesActor.SetZMinusFaceText('P')
> self.axesActor.SetZPlusFaceText('A')
> self.axesActor.GetTextEdgesProperty().SetColor(1,1,0)
> self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
> self.axesActor.GetCubeProperty().SetColor(0,0,1)
> self.axes = vtk.vtkOrientationMarkerWidget()
> self.axes.SetOrientationMarker(self.axesActor)
> self.axes.SetInteractor(iren)
> self.axes.EnabledOn()
> self.axes.InteractiveOn()
> self.ren.ResetCamera()
>
> if __name__ == "__main__":
> app = QApplication(sys.argv)
> window = SimpleView()
> window.show()
> app.exec_()
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130106/d5c39aea/attachment.htm>
More information about the vtkusers
mailing list