[PyQt] Many Sources for a Signal
Andreas Pakulat
apaku at gmx.de
Sun Feb 27 22:25:35 GMT 2011
On 27.02.11 19:06:37, Nahuel Defossé wrote:
> Hi,
>
> we're working in a tabed text editor which uses QtGui's QTabWidget to
> display a QPlainText edit for each tab.
> We needed to enable or disable some menus depending on the QTextEditor
> activity and some other
> widgets surrounding the tab widget also need to be updated (for
> example, the status bar displays the line
> and column number the text cursor is currently placed at).
> To obtain a generic way to publish events within the text editor
> without knowing possible receivers, we
> hacked QApplication.notify method [1] to notify every possible widget
> receiving that an event signature in the
> widget hierarchy chain stopping at the QMainWindow instance.
>
> In a few words, multiple sources need to send an event to unknown
> receivers, but these events have to
> be in the context of the QMainWindow widget hierarchy. What do you suggest?
Create a class that is central to your application that each part can
access. That class has notifyXYZ functions and emits signals. Then any
component can register to the signals its interested in and the
components that want to trigger the signals can use the notify functions
to notify all receivers. Hacking QApplication is not necessary for this.
Andreas
--
While you recently had your problems on the run, they've regrouped and
are making another attack.
More information about the PyQt
mailing list