Hi everybody.
I 'm looking for a simple example (with SIGNAL, SLOt and Emit()) where we have:
-a main form, say 'FormA' which opens another form, let's say 'FormB'
-FormB has a button which when clicked calls a function in FormA.
If you are aware of some example please post it here.
The terms you are using don't mean anything to anyone but yourself with the amount of information provided, see the links in my signature for how to ask better questions.
You should provide example code to help people understand your question. At least mention that you are using some version of Qt.
from PySide6 import QtWidgets, QtCore
class FormB(QtWidgets.QWidget):
form_done = QtCore.Signal(str)
def __init__(self, *args, steps=5, **kwargs):
super().__init__(*args, **kwargs)
self.entry = QtWidgets.QLineEdit("Enter value here")
self.button = QtWidgets.QPushButton("Done")
self.button.clicked.connect(self.button_pressed)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.entry)
layout.addWidget(self.button)
def button_pressed(self):
self.hide()
self.form_done.emit(self.entry.text())
class FormA(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_b = None
self.button = QtWidgets.QPushButton("Draw B")
self.button.clicked.connect(self.draw_b)
self.label = QtWidgets.QLabel("I display the result in this label")
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.button)
layout.addWidget(self.label)
def draw_b(self):
if self.form_b is None:
self.form_b = FormB()
self.form_b.form_done.connect(self.b_done)
self.form_b.show()
def b_done(self, text):
self.label.setText(text)
def main():
app = QtWidgets.QApplication([])
form_a = FormA()
form_a.show()
app.exec()
main()
Any python function/method can be bound to a signal, so the concept of Slots is kind of meaningless.
Guys thank you and forgive me for the lack of information.
deanhystad this is EXACTLY what I wanted!