PyQt4发送信号按钮点击到其他窗口

时间:2014-06-15 13:34:08

标签: python pyqt4

我有2个类创建的2个窗口,两个窗口都包含模拟。我想通过在第一个窗口中单击相同的按钮来启动它们。我应该使用类似的东西:

self.connect(self, SIGNAL("mysignal"), self.myValChanged)

            param = 100
            self.emit(SIGNAL("mysignal"), param)
第一个窗口中的

def myValChanged(val):
            print "New spin val %d" % val

在第二个窗口?它会起作用吗?怎么用?

我的代码:

class Simulation(QMainWindow):

    def __init__(self, filename, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui = uic.loadUi("gui/mainui.ui", self)
        self.ui.startButton.clicked.connect(self.onStartButtonClick)
        self.pos = [0, 0]
        self.v0 = 10.0
        self.pts = []
        self.isMoving = False
        self.force = Force()
        self.loadData(filename)
        self.movement = Movement(self.force, self.pts, self)

    def onStartButtonClick(self):
        if(self.isMoving == False):
            self.pos = [0, 0]
            self.v0 = 10.0
            self.isMoving = True
            self.move()
            #start differentmove() from second class

    def move(self):
    ...


class Simulation2(QMainWindow):

    def __init__(self, filename, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui = uic.loadUi("gui/mainui2.ui", self)
        self.ui.startButton.clicked.connect(self.onStartButtonClick)
        self.pos = [400, 0]
        self.v0 = 10.0
        self.pts = []
        self.isMoving = False
        self.force = Force()
        self.loadData(filename)
        self.movement = Movement(self.force, self.pts, self)

    def differentmove(self):
        ...    

0 个答案:

没有答案