Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you can use two different approaches here: make the <code>A</code> and <code>B</code> classes tightly coupled, or using the main-window as mediator.</p> <p>In the first case you will have to "let <code>A</code> know <code>B</code>", meaning that <code>A</code> has a reference to <code>B</code>. In this case you don't even have to do signals &amp; slots at all but you can simply call <code>B</code>'s methods directly.</p> <p>The other approach is to let <code>A</code> emit a signal <em>with an argument</em> containing the data that should be received by <code>B</code>, the main-window catches this signal and calls <code>B</code> with the data. Alternatively you can put the data in an <code>A</code>'s attribute and let the main-window take it from here directly, without passing it as signal's argument.</p> <p>The latter method allows you to write a bit more freely <code>A</code> and <code>B</code> since <code>A</code> does not have to know how to call <code>B</code>.</p> <p>Explained in code it should looks like this:</p> <pre><code>class A(QWidget): the_signal = Signal(...) def mouseReleaseEvent(self, event): self.a_function() self.the_data = self.produce_data() self.the_signal.emit() class B(QWidget): def process_data(self, data): pass class MainWindow(QMainWindow): def __init__(self): self.a_widget = A() self.b_widget = B() self.a_widget.the_signal.connect(self.do_process) # if the signal has the data as argument: # self.a_widget.the_signal.connect(self.b_widget.process_data) def do_process(self): self.b_widget.process_data(self.a_widget.the_data) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload