[PyKDE] provide custom widget to python
Jim Bublitz
jbublitz at nwinternet.com
Mon Dec 15 18:44:01 GMT 2003
On Monday December 15 2003 08:13, Jan Drugowitsch wrote:
> Hi everyone,
>
> I'm new to qt and have recently created my first custom widget
> (inherited from QScrollView) which works without any problems
> in C++ code. As I mainly use Python for the GUI work I'd like
> to provide this custom widget for use in python. As the sip
> documentation is pretty sparse and I'm not very 'informed'
> about the inner workings of Qt and how Python exactly handles
> its objects and garbage collection I still have problems
> achieving this.
>
> My .sip file declares the TokenDisplay class by inheriting
> QScollView. How do I get the reference to QScollView in there
> without including the whole qtmod.sip?
> That's the beginning of my .sip class declaration:
>
> class TokenDisplay : QScrollView
> {
> %HeaderCode
> #include "tokendisplay.h"
> %End
>
> public:
> // enumeration for TokenClicked signal
> enum MouseButton { RightButton, LeftButton };
>
> TokenDisplay(QWidget* /TransferThis/ = 0, const char* =
> 0); [snip]
>
> Without including anything I get
> sip: QScrollView has not been defined
> If I include qtmod.sip, headers and wrappers for all the qt
> classes get generated and that's not what I want.
> Although I've searched through the mailing list I'm not much
> wiser than before. Does anyone have any cues I can start with?
> Sorry if this question's already been asked several times
> before.
It's hard to give a precise answer without knowing how you've set
this up to build, but I can give you some hints. First, I assume
"tokendisplay.h" has #includes for the necessary Qt h files
(these won't generate any sip code but are necessary for
compiling) and your make file can find the Qt h files.
Second, somewhere you need to add:
%Import qtmod.sip
For PyQt and PyKDE there is normally a "top-level" sip file which
controls sip's code generation and is the file name you pass
when you invoke 'sip' to generate C++ code. It should look
something like:
%Module tokendisplay
%Import qtmod.sip
%Include tokendisplay.sip
The "top-level" sip file needs to be named something other than
"tokendisplay.sip" if that's the name of the sip file that
contains the class definition. Look at PyQt (eg qtmod.sip) or
PyKDE (eg dcop-kde*.sip, kdecore-kde*.sip) for examples of
"top-level" sip files. You'll also need to provide a path to the
PyQt sip files and link to libqtcmodule.so (-L <site-packages
path> -l qtcmodule) as well as libqt-mt.so.
The %Import will cause the generation of a lot of C++ h files by
sip, but won't generate any cpp files by itself (as %Include
would).
Nice job picking up the sip syntax - esp the /TransferThis/.
Jim
More information about the PyQt
mailing list