如何重载QToolBar.addAction()方法

时间:2015-12-24 10:01:52

标签: python-2.7 pyqt4

如何重载PyQt中的任何方法

class Main_Window( QMainWindow):
    def __init__(self, parent = None):
        super(Main_Window,self).__init__(parent)
        self.initUI()

    def initUI(self):
        dialog_window = QAction( '&Create Plugin', self
        dialog_window.triggered.connect(self.showdialog)
        toolbar = self.addToolBar('Exit')
#        toolbar.addAction(QIcon("plugin0.png"),'',self.showdialog)

我想重载QToolBar.addAction(self,QIcon图标,可调用接收器)

.........

        toolbar.addAction(QIcon("plugin0.png"),self.showdialog)
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Menubar')
        self.show()

    def showdialog(self):
        d = Dialog_window()
        d.exec_()


def main():

    app = QApplication(sys.argv)
    ex = Main_Window()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:0)

一个小小的例子......

class MyToolBar( QToolBar ) :
    """Class doc
    """

    def __init__( self, parent ) :
        """Class initialiser
        """

        QToolBar.__init__( self, parent )

    def addAction( self, icn, func ) :

        act = QAction( icon, QString(), self )
        self.addAction( act )