[PyQt] Passing a QWidget* wrapped in a PyCObject from a C++ program?

Phil Thompson phil at riverbankcomputing.com
Mon Oct 18 13:04:59 BST 2010

On Mon, 18 Oct 2010 11:45:07 +0200, Elias Bachaalany
<lallousz-pyqt4 at yahoo.com> wrote:
> Hello
> I have a C++ program that creates a QWidget* and can return that to
> I want to pass that QWidget * to PyQt so that the newly created widgets 
> have this widget as their parent. How to do that?
> In C++:
> QWidget *theWidget;
> PyObject *get_widget()
> {
>    return PyCObject_FromVoidPtr(theWidget, NULL)
> }
> Now is it possible to get this QWidget* and give to PyQt / QWidget

If your PyCObject is accessible from Python then you should be able to

import sip
from PyQt4.QtGui import QWidget

widget = sip.wrapinstance(sip.voidptr(pycobj, QWidget))


More information about the PyQt mailing list