我是一个新手在GUI设计和Python方面。
我正在尝试在我用QTDesign制作的简单GUI中显示渲染,但无法正确显示它。
渲染工作正常,但我想把渲染小部件放在主窗口(或其他任何小部件)中,但不起作用。
有人知道如何做吗?
问候! Maxi
用户界面:
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)