[PyQt] Very simple signal/slot "transference"/encapsulation?

J Barchan jnbarchan at gmail.com
Wed Jan 17 12:36:32 GMT 2018


On 17 January 2018 at 12:32, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:

> Hi Jonathan,
>
> You can connect a signal directly to another signal. So in your class
> definition:
>
> editingFinished = pyqtSignal()
>
> def __init__(self, ....):
>   .....
>   myLineEdit.editingFinished.connect(self.editingFinished)
>
> Hope this helps,
>
> Denis
>
>
>
> Le mer. 17 janv. 2018 à 07:54, J Barchan <jnbarchan at gmail.com> a écrit :
>
>> I inherited code using a QLineEdit.  I have to change that into a (what
>> I call) a "composite" widget, consisting of a QWidget which holds a
>> QHBoxLayout which in turn holds the original QLineEdit, plus a
>> QPushButton; the button leads to something which can populate the
>> QLineEdit.
>>
>> I'm OK with the design, apart from signal/slot handling.  The outside
>> world used to go QLineEdit.editingFinished.connect(...).  To
>> encapsulate, I'd like it to go CompositeWidget.
>> editingFinished.connect(...), rather than addressing the QLineEdit
>> directly.  So I want to simply "transfer" the *existing* editingFinshed
>> signal/slot from the QLineEdit to the CompositeWidget level,
>> "transparently".
>>
>> This is for PyQt 5 only, not earlier versions.  So far I've never had to
>> use PyQt @ annotations (@pySignal/Slot or whatever they are), and I'm
>> not sure I ought need to, given the definition in QLineEdit in
>> QtWidgets.pyi is already as plain as
>>
>> def editingFinished(self) -> None: ...
>>
>> ​So, given that I regard minimal code as neat/desired, what is like the
>> *minimum* I need to write​ to achieve this?  I will need the outside
>> world to be able to connect(), my widget needs to be able to emit() it
>> (when the user has finished interacting via the button, widget populates
>> the QLineEdit and needs that to raise editingFinished signal to the
>> outside world).  I think that's it!
>>
>> --
>> Kindest,
>> Jonathan
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
​
Oohhh, that looks fairly neat and simple!  And my code editor should still
see the editingFinished as a member (variable) of my class, for code
completion.

I'll try this later today and see, thanks... !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180117/7977b19a/attachment.html>


More information about the PyQt mailing list