4

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)
4

2 回答 2

2

你看到这个例子了吗?它适用于我将 PySide 换成 PyQt。 http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt

于 2013-11-27T22:55:00.717 回答
1

要在 Widget 中渲染,请使用 QVTKRenderWindowInteractor 类。首先,进入这里:

https://svn.enthought.com/enthought/browser/Mayavi/trunk/enthought/tvtk/pyface/ui/qt4/QVTKRenderWindowInteractor.py?rev=20906

你可以做两件事。

第一个选项:

一个。像往常一样创建你的 Qt 窗口。

湾。创建 QVTKRenderWindowInteractor 的实例并将其设置为您想要包含它的小部件/窗口的父级。

self.myViewer= QVTKRenderWindowInteractor(self.parentWidget)

QVTKRenderWindowInteractor 是 vtkRenderWindowInteractor 的包装器,您可以像这样得到渲染窗口:

self.myViewer.GetRenderWindow()

第二种选择:

您可以使用 QtDesigner 将您的小部件提升为 QVTKRenderWindowInteractor

于 2013-10-30T18:35:10.593 回答