将从方法类发出的信号连接到不同的类槽自定义信号PySide

时间:2017-07-18 11:49:15

标签: python signals pyqt4 pyside signals-slots

我想将closeWidgetUI类方法发出的信号连接到addTool类方法。但这似乎只适用于PyQt4,而不适用于PySide。每次我点击在self.close_btn.clicked.connect(self.closeWidgetUI)中创建的closeButton时,程序都会冻结并自行关闭。任何消化?

import PySide.QtCore as qc
import PySide.QtGui  as qg

class InterpolateIt(dc,qg.QDialog):
    def __init__(self):
        qg.QDialog.__init__(self)

        """ MORE THINGS 
        OVER THIS PART NOT IMPORTANT AT MOMENT"""

        add_button.clicked.connect(self.addTool)

    def addTool(self):

        #NEED TO CONNECT closeWidgetUI EMITED SIGNAL HERE 
        new_widget = InterpolateWidget()
        self.clicked.connect(new_widget, qc.SIGNAL('CLOSE'), self.removeTool)

    def removeTool(self,interpWidget):
        self.interpolateLayout.removeWidget(interpWidget)
        interpWidget.deleteLater()


# ------------------------------------------------------------------------------------------------------#        
class InterpolateWidget(qg.QFrame):
    def __init__(self):
        qg.QFrame.__init__(self)

        """ MORE THINGS 
        OVER THIS PART NOT IMPORTANT AT MOMENT"""

        # HERE BUTTON EMIT SIGNAL AT CLICKED
        self.close_btn.clicked.connect(self.closeWidgetUI)

        # TRIGGER THIS FUNC
    def closeWidgetUI(self):
        self.emit(qc.SIGNAL('CLOSE'), self)

1 个答案:

答案 0 :(得分:0)

from functools import partial

 def addTool(self):

        #NEED TO CONNECT closeWidgetUI EMITED SIGNAL HERE 
        new_widget = InterpolateWidget()
        deleteTool = partial(self.removeTool,new_widget)
        new_widget.close_btn.clicked.connect(deleteTool)
我是这样做的!感谢我的大脑:)干杯