I'm not sure how to have a signal be passed between two different classes. I want classA button custom signal to show classB button !! (self.butt2.setVisible(True)) the Code is as following:
from PyQt4 import QtGui,QtCore
import sys
class A(QtGui.QWidget):
customSignal = QtCore.pyqtSignal(str)
def __init__(self,parent=None):
super(A,self).__init__(parent)
self.applyButton = QtGui.QPushButton('Apply')
mLayout = QtGui.QHBoxLayout()
mLayout.addWidget(self.applyButton)
self.setLayout(mLayout)
self.applyButton.clicked.connect(self.emitSignal)
self.customSignal.connect(self.printStr)
def emitSignal(self):
self.customSignal.emit('classA')
def printStr(self):
print 'this is class A'
class B(QtGui.QWidget):
def __init__(self,parent=None):
super(B,self).__init__(parent)
self.butt1 = QtGui.QPushButton('abc')
self.butt2 = QtGui.QPushButton('def')
self.butt2.setVisible(False)
mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.butt1)
mainLayout.addWidget(self.butt2)
self.setLayout(mainLayout)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
a = A()
a.show()
b = B()
b.show()
sys.exit(app.exec_())
Assuming you want the class A button to toggle the visibility of the class B button:
a.customSignal.connect(lambda: b.setVisible(not b.isVisible()))