[PyQt] Creating custom widget for designer

Jorge Tornero jtorlistas at gmail.com
Fri Aug 29 13:45:26 BST 2014


Hi Florian,

Thank you for your wise advice. When I was asking precisely for what's
better from a clean code perspective.

I've made the widget again whitout the "nested classes" and it works
perfectly.

Thank you very much

Jorge Tornero


2014-08-29 9:41 GMT+02:00 Florian Bruhin <me at the-compiler.org>:

> Hi,
>
> * Jorge Tornero <jtorlistas at gmail.com> [2014-08-21 04:59:10 +0200]:
> > Dear all,
> > I've created a  custom widget which can be used from within designer-qt4,
> > following the few recipes available out there.
> >
> > It works as expected but, because I'm not a pro, I'm looking for some
> > advice on the way I've implemented the widget.
> >
> > Basically: the base class is a QLineEdit in which a key event triggers a
> > Qdialog which has customized QComboBox inside. Therefore I've implemented
> > the widget as a single  class in this fashion (simplified)
> >
> > class myLineEdit(QLineEdit):
> >    class myPopupDialog(QDialog):
> >
> >         class myCustomCombo(QComboBox):
> >                (Definition of myCustomCombo goes here)
> >        (Definition of mypopupdialog goes here, including some
> customcombos)
> >
> >     (Defi ition of mylineedit goes here including key event handler
> > that execs a mypopupdialog)
> >
> > This, say so, class-!nesting schema is very strange to me, so let me
> > ask you if this is a correct way of implementing such widgets,
> > providing they're going to be used as designer plugins.
> >
> > Thank you very much for your advice
>
> I don't know anything about designer plugins, so this is more from the
> general Python perspective:
>
> This certainly works - I sometimes use it for small helper functions.
> It seems like it works fine with classes as well.
>
> However, IMHO it would be cleaner to just define multiple classes in a
> module, all on the toplevel, like this:
>
>
> class myCustomCombo(QComboBox):
>    (Definition of myCustomCombo goes here)
>
>
> class myPopupDialog(QDialog):
>    (Definition of mypopupdialog goes here, including some
>     customcombos)
>
>
> class myLineEdit(QLineEdit):
>     (Definition of mylineedit goes here including key event handler
>      that execs a mypopupdialog)
>
>
> Florian
>
> --
> http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
>              GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
>          I love long mails! | http://email.is-not-s.ms/
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140829/e4c4668b/attachment.html>


More information about the PyQt mailing list