pyqt QAction strange behavior of the function call -
i make simple window , added menu , toolbar. , got strange behavior of function connected action. here's code:
import os import sys import sip import maya.openmayaui mui pyqt4.qtcore import * pyqt4.qtgui import * pyqt4 import uic #---------------------------------------------------------------------- def getmayawindow(): ptr = mui.mqtutil.mainwindow() return sip.wrapinstance(long(ptr), qobject) #---------------------------------------------------------------------- class mainform(qmainwindow): def __init__(self): super(mainform, self).__init__(getmayawindow()) self.setgeometry(50,50,600,600) mdiarea = qmdiarea() self.setcentralwidget(mdiarea) self.testaction = qaction(qicon('ico.png'), '&test', self) self.testaction.triggered.connect(self.aaaaa) self.menubar = self.menubar() filemenu = self.menubar.addmenu('&file') filemenu.addaction(self.testaction) self.toolbar = self.addtoolbar('exit') self.toolbar.addaction(self.testaction) self.statusbar() def aaaaa(self): print('test') #---------------------------------------------------------------------- # window def cachewnd(): wnd = mainform() wnd.show() cachewnd()
when press menu or toolbar icon - associated function not called. necessary make global function outside class , make call without self how starts work immediately.
i correct line:
self.testaction.triggered.connect(aaaaa)
and drag function outside class:
def aaaaa(): print('test')
and @ once started, called , running...
why not work until function member of class?
Comments
Post a Comment