如何传输为widget graphicViewPloted(widget)绘制的图形?蟒蛇

时间:2012-08-30 19:57:31

标签: python graph qt4 plot pyqt4

我正在尝试将我的senoide图转移到widget graphcsView,但我无法将该图与widget关联起来。我使用QT Desing制作GUI并使用pyuic生成代码。我可以绘制图形,但不能插入框中以查看图形到GUI。 拜托,有人能帮助我吗?

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'plot.ui'
#
# Created: Thu Aug 30 13:42:21 2012
#      by: PyQt4 UI code generator 4.8.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from pylab import*
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
     _fromUtf8 = lambda s: s

class Ui_ploting(object):
    def setupUi(self, ploting):
        ploting.setObjectName(_fromUtf8("ploting"))
        ploting.resize(400, 300)
        ploting.setWindowTitle(QtGui.QApplication.translate("ploting", "Ploting", None,  QtGui.QApplication.UnicodeUTF8))
        self.pushButtonPlot = QtGui.QPushButton(ploting)
        self.pushButtonPlot.setGeometry(QtCore.QRect(10, 40, 75, 23))
        self.pushButtonPlot.setText(QtGui.QApplication.translate("ploting", "Plot",   None, QtGui.QApplication.UnicodeUTF8))
        self.pushButtonPlot.setObjectName(_fromUtf8("pushButtonPlot"))
        self.graphicsViewPloted = QtGui.QGraphicsView(ploting)
        self.graphicsViewPloted.setGeometry(QtCore.QRect(120, 30, 271, 251))
        self.graphicsViewPloted.setObjectName(_fromUtf8("graphicsViewPloted"))

        self.retranslateUi(ploting)
        QtCore.QObject.connect(self.pushButtonPlot, QtCore.SIGNAL(_fromUtf8("clicked()")), self.ploting)
        QtCore.QMetaObject.connectSlotsByName(plot_1)


    def plot_1(self):
        x=arange(0,2,0.01)
        y=2*sin(2*pi*(x-1/4))
        plot(x,y)
        show()

    def retranslateUi(self, ploting):
        pass


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ploting = QtGui.QWidget()
    ui = Ui_ploting()
    ui.setupUi(ploting)
    ploting.show()
    sys.exit(app.exec_())

0 个答案:

没有答案