[PyQt] Create QMenus in different files
Patrick Stinson
patrickkidd at gmail.com
Fri Nov 17 18:57:59 GMT 2017
Alain,
The first method is sufficient. Be sure that you are calling the class’s superclass constructor or it will complain that the instance is “not a QMenu.” For example:
class MyMenu(QMenu):
def __init__(self, parent=None):
super().__init__(parent)
-Patrick
> On Nov 17, 2017, at 10:53 AM, Alain Muls <alain.muls at gmail.com> wrote:
>
> Hi All
>
> I just started out with pyQt5 but I have experience with Qt and C++.
>
> I try to separate my code in different files for not getting files that are too long. Therefor I am looking to a way that I can create the different QMenus (so 'file', 'edit', 'Help', etc) in separate files. I tried several things
>
> subclassing QMenu and then create in the main GUI part an instance that I add to the QMenuBar
>
> create a function in a different file that returns a QMenu that I add to the QMenuBar
>
> but both methods didn't show the added menu in my menubar.
>
> The first method had as problem that the derived class was not a QMenu, so could not be added.
> I tried second methods since in the documentation of QMenuBar I found:
>
> QAction addMenu <http://pyqt.sourceforge.net/Docs/PyQt4/qmenubar.html#addMenu> (self, QMenu menu)
>
> So it should be possible to add a QMenu (second method).
> Does someone has such an example?
>
> Tx for your help
>
> Alain
> --
>
> <logorma-transparent-scaled.png>
> Alain Muls
> Professor
> Department CISS
> Royal Military Academy
> p: +32 244 13936
> a: Renaissance Avenue 30
> B1000 Brussels (Belgium)
> w: www.rma.ac.be/ciss/en/ <http://www.rma.ac.be/ciss/en/> e: alain.muls at rma.ac.be <mailto:alain.muls at rma.ac.be>_______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171117/e4085f12/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1403 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171117/e4085f12/attachment-0001.bin>
More information about the PyQt
mailing list