[PyQt] Equivalent of Q_PROPERTY's MEMBER for pyqtProperty?

Elvis Stansvik elvstone at gmail.com
Sun Nov 11 14:02:02 GMT 2018

Den sön 11 nov. 2018 kl 14:38 skrev Kyle Altendorf <sda at fstab.net>:
> As I remember it's a mess but that sounds like my @pyqtify (oh what a bad name...) Decorator for @attr.s classes.  I use it to create signals so my attrsmodel (for tree views) can be backed by attrs classes.
> https://github.com/altendky/stlib/blob/399f3119576ee4e6f9310d646f08c8eb221f0dcd/epyqlib/tests/utils/test_qt.py
> https://github.com/altendky/stlib/blob/399f3119576ee4e6f9310d646f08c8eb221f0dcd/epyqlib/utils/qt.py
> Basically for each attrs attribute it creates a property (Python by default, you can specify pyqtProperty instead if you want).  The property is used to emit a signal on change.  A separate object is created to house the signals and is accessible via epyqlib.utils.qt.pyqtify_signals().  In my case mostly I don't write that much because it's just backend in my model.
> Hopefully someday I'll tidy up my library so it's a bit easier to follow and try out.  Sorry.

Ah, thanks for the pointer at least. In my case I was just porting
some C++ code that happened to use MEMBER for one particular property,
so it was no problem to just spell out the setter/getter/signal
emission instead.


> Cheers,
> -kyle
> On November 11, 2018 6:14:00 AM EST, Elvis Stansvik <elvstone at gmail.com> wrote:
> >Hi all,
> >
> >E.g. in C++ one can do:
> >
> >    Q_PROPERTY(bool showFileDialog MEMBER m_showFileDialog NOTIFY
> >showFileDialogChanged)
> >...
> >public:
> >    bool m_showFileDialog = false;
> >...
> >signals:
> >    void showFileDialogChanged();
> >
> >This makes the m_showFileDialog member variable readable and writable
> >without the need of creating READ and WRITE accessor functions, and Qt
> >emits automatically the showFileDialogChanged signal when needed.
> >
> >Is it possible to get this kind of convenience with PyQt?
> >
> >Cheers,
> >Elvis
> >_______________________________________________
> >PyQt mailing list    PyQt at riverbankcomputing.com
> >https://www.riverbankcomputing.com/mailman/listinfo/pyqt

More information about the PyQt mailing list