I´m new in designing GUIs and Python
I´m trying to display a render in a simple GUI I made with QTDesign but doesn't display it properly.
The rendering works but I want the rendering widget inside a main window (or inside any other widget?) but doesn't work.
Does anybody know how to do it?
Regards! Maxi
The UI:
from PySide import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(455, 380)
MainWindow.setMinimumSize(QtCore.QSize(455, 380))
MainWindow.setMaximumSize(QtCore.QSize(455, 380))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(365, 340, 75, 23))
self.pushButton.setObjectName("pushButton")
self.frame = QtGui.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(20, 20, 416, 306))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
The main program....
from Prueba_Viewer import Ui_MainWindow
import vtk
from PySide import QtGui
from PySide import QtCore
import sys
import os
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
class MaxWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
#self.ui = Ui_main()
#self.ui.setupUi(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.meshDisplayWidget = QVTKRenderWindowInteractor(self.ui.frame)
self.ui.meshDisplayWidget.Initialize()
#Set actors and mappers, then instead of creating a renderwindowinteractor,
#use the self.ui.meshDisplayWidget to display the mesh. Also define picker, and
#set data source (for code about displaying a mesh from coordinates, as
#an unstructured grid.
cone = vtk.vtkConeSource()
cone.SetResolution(28)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren = vtk.vtkRenderer()
ren.AddActor(coneActor)
ren.ResetCamera()
cam1 = ren.GetActiveCamera()
self.ui.meshDisplayWidget.GetRenderWindow().AddRenderer(ren)
#self.ui.meshDisplayWidget.SetPicker(picker_point)
self.ui.meshDisplayWidget.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
maxwin = MaxWindow()
Max_Window = maxwin
maxwin.show()
exit_code = app.exec_()
sys.exit(exit_code)