[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Create QMenus in different files
From:       Patrick Stinson <patrickkidd () gmail ! com>
Date:       2017-11-17 18:57:59
Message-ID: EE8CB1FD-EF05-48FE-AFFF-E1C4C278A6BB () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/alternative)]


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@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@rma.ac.be \
> <mailto:alain.muls@rma.ac.be>_______________________________________________ PyQt \
> mailing list    PyQt@riverbankcomputing.com \
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[Attachment #7 (unknown)]

<html><head><meta http-equiv="Content-Type" content="text/html; \
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
line-break: after-white-space;" class="">Alain,<div class=""><br class=""></div><div \
class="">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:</div><div class=""><br class=""></div><div class="">class \
MyMenu(QMenu):</div><div class="">&nbsp; &nbsp; def __init__(self, \
parent=None):</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; \
super().__init__(parent)</div><div class=""><br class=""></div><div \
class="">-Patrick</div><div class=""><br class=""><div><br class=""><blockquote \
type="cite" class=""><div class="">On Nov 17, 2017, at 10:53 AM, Alain Muls &lt;<a \
href="mailto:alain.muls@gmail.com" class="">alain.muls@gmail.com</a>&gt; \
wrote:</div><br class="Apple-interchange-newline"><div class="">  

    <meta http-equiv="content-type" content="text/html; charset=utf-8" class="">
  
  <div text="#000000" bgcolor="#FFFFFF" class=""><p class="">Hi All</p><p class="">I \
                just started out with pyQt5 but I have experience with Qt and
      C++.</p><p class="">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</p>
    <ul class="">
      <li class="">subclassing QMenu and then create in the main GUI part an
        instance that I add to the QMenuBar<br class="">
        <br class="">
      </li>
      <li class="">create a function in a different file that returns a QMenu
        that I add to the QMenuBar<br class="">
        <br class="">
      </li>
    </ul><p class="">but both methods didn't show the added menu in my menubar.</p><p \
class="">The first method had as problem that the derived class was not a  QMenu, so \
could not be added.<br class="">  </p><p class="">I tried second methods since in the \
documentation of QMenuBar I  found:</p><p class=""><span style="font-variant-caps: \
normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; \
text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: \
0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: \
none; display: inline !important;" class="">QAction<span \
class="">&nbsp;</span></span><b style="font-variant-caps: normal; letter-spacing: \
normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; \
white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; \
background-color: rgb(255, 255, 255);" class=""><a \
href="http://pyqt.sourceforge.net/Docs/PyQt4/qmenubar.html#addMenu" style="color: \
rgb(103, 41, 103); text-decoration: none;" class="">addMenu</a></b><span \
style="font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: \
2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; \
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: \
rgb(255, 255, 255); float: none; display: inline !important;" class=""><span \
class="">&nbsp;</span>(</span><i style="font-weight: 400; letter-spacing: normal; \
orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: \
normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; \
background-color: rgb(255, 255, 255);" class="">self</i><span \
style="font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: \
2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; \
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: \
rgb(255, 255, 255); float: none; display: inline !important;" class="">, \
QMenu&nbsp;</span><i style="font-weight: 400; letter-spacing: normal; orphans: 2; \
text-align: left; text-indent: 0px; text-transform: none; white-space: normal; \
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: \
rgb(255, 255, 255);" class="">menu</i><span style="font-variant-caps: normal; \
font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: \
0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; \
display: inline !important;" class="">)</span></p>  <span style="font-variant-caps: \
normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; \
text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: \
0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: \
none; display: inline !important;" class="">So it should be possible to add a QMenu  \
(second method).<br class="">  </span><p class="">Does someone has such an \
example?</p><p class="">Tx for your help</p><p class="">Alain<br class="">  </p>
    <div class="moz-signature">-- <br class="">
      <br class="">
      <table style="background: none; border-width: 0px; border: 0px;
        margin: 0; padding: 0; border-collapse: collapse; border-top:
        1pt solid #F7751F; padding-top: 2px;" cellspacing="0" cellpadding="0" \
border="0" class="">  <tbody class="">
          <tr class="">
            <td style="padding-top: 0; padding-bottom: 0; padding-left:
              0; padding-right: 7px; border-top: 0; border-bottom: 0:
              border-left: 0; border-right: solid 3px #F7751F" valign="top" \
class=""><span id="cid:part2.3D9DECBB.8372DBA7@gmail.com">&lt;logorma-transparent-scaled.png&gt;</span></td>
  <td style="padding-top: 0; padding-bottom: 0; padding-left:
              12px; padding-right: 0;" class="">
              <table style="background: none; border-width: 0px; border:
                0px; margin: 0; padding: 0;" cellspacing="0" cellpadding="0" \
border="0" class="">  <tbody class="">
                  <tr class="">
                    <td colspan="2" style="padding-bottom: 5px; color:
                      #F7751F; font-size: 14px; font-family: Arial,
                      Helvetica, sans-serif;" class=""><strong class="">Alain \
Muls</strong></td>  </tr>
                  <tr class="">
                    <td colspan="2" style="color: #333333; font-size:
                      11px; font-family: Arial, Helvetica, sans-serif;" class=""><i \
class="">Professor</i></td>  </tr>
                  <tr class="">
                    <td colspan="2" style="color: #333333; font-size:
                      11px; font-family: Arial, Helvetica, sans-serif;" \
class="">Department  CISS</td>
                  </tr>
                  <tr class="">
                    <td colspan="2" style="color: #333333; font-size:
                      11px; font-family: Arial, Helvetica, sans-serif;" \
class=""><strong class="">Royal  Military Academy</strong></td>
                  </tr>
                  <tr class="">
                    <td style="vertical-align: top; width: 20px; color:
                      #F7751F; font-size: 11px; font-family: Arial,
                      Helvetica, sans-serif;" valign="top" width="20" \
class="">p:</td>  <td style="vertical-align: top; color: #333333;
                      font-size: 11px; font-family: Arial, Helvetica,
                      sans-serif;" valign="top" class="">+32 244 13936</td>
                  </tr>
                  <tr class="">
                    <td style="vertical-align: top; width: 20px; color:
                      #F7751F; font-size: 11px; font-family: Arial,
                      Helvetica, sans-serif;" valign="top" width="20" \
class="">a:</td>  <td style="vertical-align: top; color: #333333;
                      font-size: 11px; font-family: Arial, Helvetica,
                      sans-serif;" valign="top" class="">Renaissance Avenue 30</td>
                  </tr>
                  <tr class="">
                    <td style="vertical-align: top; width: 20px; color:
                      #F7751F; font-size: 11px; font-family: Arial,
                      Helvetica, sans-serif;" valign="top" width="20" \
class="">&nbsp;</td>  <td style="vertical-align: top; color: #333333;
                      font-size: 11px; font-family: Arial, Helvetica,
                      sans-serif;" valign="top" class="">B1000 Brussels \
(Belgium)</td>  </tr>
                  <tr class="">
                    <td style="vertical-align: top; width: 20px; color:
                      #F7751F; font-size: 11px; font-family: Arial,
                      Helvetica, sans-serif;" valign="top" width="20" \
class="">w:</td>  <td style="vertical-align: top; color: #333333;
                      font-size: 11px; font-family: Arial, Helvetica,
                      sans-serif;" valign="top" class=""><a \
href="http://www.rma.ac.be/ciss/en/" style="  color: #1da1db; text-decoration: none;
                        font-weight: normal; font-size: 11px;" \
class="">www.rma.ac.be/ciss/en/</a>&nbsp;&nbsp;<span style="color: #F7751F;" \
class="">e:&nbsp;</span><a href="mailto:alain.muls@rma.ac.be" style="color:  #1da1db; \
                text-decoration: none; font-weight:
                        normal; font-size: 11px;" \
class="">alain.muls@rma.ac.be</a></td>  </tr>
                </tbody>
              </table>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

_______________________________________________<br class="">PyQt mailing list \
&nbsp;&nbsp;&nbsp;<a href="mailto:PyQt@riverbankcomputing.com" \
class="">PyQt@riverbankcomputing.com</a><br class=""><a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
class="">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></div></blockquote></div><br \
class=""></div></body></html>


["smime.p7s" (smime.p7s)]

0	*H
 010	+0	*H
 e0a0I 0
	*H
0M10UPatrick Stinson10	UUS1$0"	*H
	patrickkidd@gmail.com0
170413045030Z
180413045030Z0M10UPatrick Stinson10	UUS1$0"	*H
	patrickkidd@gmail.com0"0
	*H
0
Dzxdh=FC4i4${P0pRrveL*[t.Sg)<SS`n@`h5L={8rH4i3=/EZ|]l<V
 t:W,ʌrJ \
G1Β%^vݼ͓ëV)~}rՍ*p+bQ!b\?V;T68n2z:jP1\tA~BsL0J0U0U%0
 +0 U0patrickkidd@gmail.com0
	*H
~
W)sS͜Iqtb<&fMDb.^\<R:~w4ίe8&ؒlM91m9ιKn}Nd'e]_vC\xE4D,K>
 ~oH,sq6p4p"dYD(Ck_GB)| 86yDv t \
̵eR0rLw ^+JclMD \
s100R0M10UPatrick Stinson10	UUS1$0"	*H \
	patrickkidd@gmail.com0	+ ]0	*H 	1	*H
0	*H
	1
171117185759Z0#	*H
	1m-+a%I60
	*H
MY_T啔t[E갢12I:QY
%RwI%m#fB~=)]@A(!\\K/z!Am	&1W2[z@7VBwݟyI3 \
QSzUli-\yR=BtfAx^J-H \
}틩CB`/ebJ=CgV_6Hhe(C ے=eىQ]J@


[Attachment #9 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic