[PyQt] Is it possible to get base class references?
rjfrank at ensight.com
Mon Apr 15 16:34:28 BST 2013
I was not sure how to title this one, but here are the details.
I have a C++ application with an embedded Python interpreter.
I have a QMainWindow (created in C++) for which I have a reference
in PyQt. Now, I would like to be able to manipulate the QMenuBar
(and children) from PyQt. I can get the QMenuBar reference just
fine in PyQt and I can walk some of the children of the QMenu I
am interested in, but many are missing. Now, in C++, I have
subclassed QAction to add some additional features and these
QAction subclasses do not show up when I try to get the list of
children of the QMenu. Ok, so I do not have a SIP wrapper for
these QAction classes. In PyQt, I would like to be able to get
references to these objects using the first class known to PyQt.
Is this possible?
In my example, 'top' is a QMainWindow instance that was
created in C++:
s = m.title()
print i+"Menu: "+str(s)
for t in m.children():
if (type(t) == PyQt4.QtGui.QMenu):
tmp = i+" "
elif (type(t) == PyQt4.QtGui.QAction):
print i+" Action: "+t.text()
menubar = top.menuBar()
for m in menubar.children():
if (type(m) == PyQt4.QtGui.QMenu):
q = m
print "Query menu:",q
The missing QAction subclasses were created in C++ using a
class MenuActionItem : public QAction, public QEnsI18N
MenuActionItem(QObject * parent);
When the QMenu ('q') above was created, it includes MenuActionItem
instances. I really do not want to expose the QEnsI18N methods via
SIP, so is there any mechanism via which I can have my MenuActionItem
instances show up in PyQt as QAction references?
Randall Frank rjfrank at ceisoftware.com 919-363-0883
Computational Engineering International www.ceisoftware.com
2166 North Salem Street, Suite 101, Apex, NC 27523-6456
More information about the PyQt