1

我正在尝试将我的 senoide 图转移到小部件 graphcsView,但我无法将该图与小部件联系起来。我使用 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_())
4

0 回答 0