[PyKDE] Problems with a port of C++/Qt book to Python

Douglas Soares de Andrade dsa at unilestemg.br
Mon Jul 18 16:48:13 BST 2005


Hi !

Another problem:

What about this construction ?

class FindDialog :  public QDialog
{
	Q_OBJECT
	
	public:
		FindDialog(QWidget *parent, const char *name = 0);

All is clear for me, but what about the Q_OBJECT macro ? How to use it in 
PyQt ?

Another thing... 

How to use the tr() function ? 
How to use this setCaption() in the code below, do i have to use self, or 
QDialog ? 
And, in the connect line, what to do with the this keyword ?

FindDialog::FindDialog(QWidget *parent, const char *name)
    : QDialog(parent, name)
{
    setCaption(tr("Find"));

    label = new QLabel(tr("Find &what:"), this);
    lineEdit = new QLineEdit(this);
    label->setBuddy(lineEdit);

    caseCheckBox = new QCheckBox(tr("Match &case"), this);
    backwardCheckBox = new QCheckBox(tr("Search &backward"), this);

    findButton = new QPushButton(tr("&Find"), this);
    findButton->setDefault(true);
    findButton->setEnabled(false);

    closeButton = new QPushButton(tr("Close"), this);

    connect(lineEdit, SIGNAL(textChanged(const QString &)),
            this, SLOT(enableFindButton(const QString &)));
    connect(findButton, SIGNAL(clicked()),
            this, SLOT(findClicked()));
    connect(closeButton, SIGNAL(clicked()),
            this, SLOT(close()));


Thanks for all the help !


Em Seg 18 Jul 2005 18:07, Eron Lloyd escreveu:
> On Monday 18 July 2005 11:01 am, Douglas Soares de Andrade wrote:
> > Hi !
> >
> > Im trying to make a port of the book C++ GUI programming with Qt to
> > Python. I alrealdy did the first chapter, but i tried to port the example
> > in the section Subclassing Qt, but i have no success.
> >
> > Some part of the cpp code is a little complicated to me, as this example:
> >
> > FindDialog::FindDialog(QWidget *parent, const char *name) :
> > QDialog(parent, name)
> >
> > As i understood, it is a implementation of the constructor, but i cant
> > get the idea in how to port it to python.
> >
> > Can someone here can help me or translate this example to python, so i
> > will do the rest, since it is most equal in the rest of the book.
> >
> > The code is here:
> >
> > http://www.unilestemg.br/find.tar.gz
> >
> > Thank you all so much for any help.
>
> Hi Douglas,
>
> Quite an ambitious project! What you see there is a typical class
> constructor. In PyQt, you would want something along the lines of:
>
> class FindDialog(QDialog):
>     def __init__(self, parent, name):
>         QDialog.__init__(self, parent, name)
>
> What it is doing is defining the FindDialog constructor, accepting the
> arguments parent and name, initializing its superclass QDialog, and passing
> it the two arguments.
>
> There is quite a bit of complicated C++ in the later chapters. Are you
> going to be able to handle it? What would be nice is a detailed translation
> guide for Qt/C++ to PyQt/Python. I started something along those lines,
> building on the work done in the appendix of the PyQt book. On that
> thought, it probably would be a better idea to update the PyQt book, and
> perhaps begin reshaping it for (Py)Qt4!
>
> Eron
>
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

-- 
Douglas Soares de Andrade
dsa at unilestemg.br
UnilesteMG - www.unilestemg.br
ICQ, MSN = 76277921, douglas at tuxfamily.org




More information about the PyQt mailing list