neydroydrec
neydroydrec

Reputation: 7313

How to implement Qt4 widgets written in C++ into some Python code?

In I my attempts at creating a GUI (a document viewer) with PyQt4, failing reproduce the quality of existing programs, it has been suggested I should use those existing program's Qt4 Widgets (Okular's to be precise), rather than re-inventing the wheel.

Fair enough, but those Qt4 widgets are written in C++: how am I supposed to call them from the Python side? And does it require me to learn C (in which case I'd rather put more time in figuring out a fully Pythonic solution)?

Upvotes: 0

Views: 191

Answers (1)

mata
mata

Reputation: 69022

Qt isn't written in C, its's written in C++, and so is Okular.

Unfortunately getting C++ libraries to work with python is not as easy as using C libraries through ctypes. To do that, you'll need to write some wrapper code around the C++ APIs to get it working.
Some ways to do that:

  • sip - used by PyQt
  • shiboken - used by PySide
  • cython can also be used to wrap C++, don't know if it plays well with Qt

Upvotes: 1

Related Questions