File: python_cpp.rst

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (26 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Mixing PyQt and C++ Widgets
================================================================================
.. currentmodule:: ost.gui

PyQt5 is a set of Python bindings for Qt5. The exposure from C++ to Python is 
done with SIP, which has a different mechanism than boost::python.
 
To access a exported boost::python Qt-Object from Python we provide a method 
which wraps the Object into a Python SIP Object.

.. code-block:: python
   
  seq_viewer = gui.SequenceViewer() # Create SequenceViewer Object
  qobj = seq_viewer.qobject #Get Python SIP Object
  print(qobj.size())   # Call function on QWidget

The other way around, each boost::python Qt Object accepts Python objects as 
input for Qt Objects. It handles the cast to a C++ Qt Object internally.

.. code-block:: python
  
  from PyQt5 import QtWidgets
  persp = gui.GostyApp.Instance().perspective
  test = persp.GetMenu("Test") #Get boost::python qobject
  test_action = QtWidgets.QAction('&Test me', test) #Create Python SIP Object
  test.addAction(test_action) #Add Action to boost::python object