Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PySide2.QtWidgets import QPushButton, QWidget, QApplication, QVBoxLayout
- from PySide2.QtCore import Signal
- import sys
- class Window(QWidget):
- def __init__(self):
- super(Window, self).__init__()
- mainlayout = QVBoxLayout(self)
- button = MyButton("Test string")
- button.clickAction.connect(self.buttonAction) # catch our signal
- mainlayout.addWidget(button)
- def buttonAction(self, buttonText): # function gets the signal string by default
- print(buttonText)
- class MyButton(QPushButton):
- clickAction = Signal(str) # signal prepared for button text
- def __init__(self, buttonText):
- super(MyButton, self).__init__()
- self.setText(buttonText)
- self.clicked.connect(self.emmitMySignal)
- def emmitMySignal(self):
- self.clickAction.emit(self.text()) # emit signal with text
- app = QApplication(sys.argv)
- win = Window()
- win.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement