title: Adding an item in matplotlib´s toolbar
body: <p>I created a matplotlib´s figure in a <code>QMainWindow</code>, using PyQt and I am trying to add a button to the matplotlib´s toolbar in my code. This is the <code>NavigationToolbar</code> that I created:</p>
  
  <p><a href="https://i.stack.imgur.com/tOYI0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tOYI0.jpg" alt="enter image description here"></a></p>
  
  <p>I added those buttons using the <code>addWidget</code> method. But, what I need is to create an Icon and put it on the toolbar. This is some part of my code:</p>
  
  <pre><code>class A(QMainWindow):
    def __init__(self):
      QMainWindow.__init__(self)
  
      self.mainWidget = QWidget()
      self.setCentralWidget(self.mainWidget)
      layout = QVBoxLayout()
      self.mainWidget.setLayout(layout)
  
      self.figure_canvas = FigureCanvas(Figure())
      layout.addWidget(self.figure_canvas, 10)
  
      self.axes = self.figure_canvas.figure.add_subplot(111)
  
      self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)
      self.addToolBar(Qt.TopToolBarArea, self.navigation_toolbar) 
  
      self.btn_selection_tool3 = QPushButton(, "Connect")
      self.navigation_toolbar.addWidget(self.btn_selection_tool3)
  
      self.btn_selection_tool2 = QPushButton()
      self.navigation_toolbar.addWidget(self.btn_selection_tool2)
  
      self.btn_showgrid = QPushButton("Show Grid")
      self.navigation_toolbar.addWidget(self.btn_showgrid)
  
      self.btn_hidegrid = QPushButton("Hide Grid")
      self.navigation_toolbar.addWidget(self.btn_hidegrid)
  
  app = QApplication(sys.argv)
  window = A()
  window.show()
  sys.exit(app.exec_())
  </code></pre>
  
  <p>I saw some codes and questions made, and I found these, but I could not accomplish what I need. These are the links that I read:</p>
  
  <p><a href="http://dalelane.co.uk/blog/?p=778" rel="nofollow noreferrer">dale lane - customize navigation toolbar</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12695678/how-to-modify-the-navigation-toolbar-easily-in-a-matplotlib-figure-window?lq=1">Modify the toolbar</a></p>
  
  <p>The links only told me how to delete some of them, and one works with wx.</p>
  
  <p>How can I add these buttons in the toolbar, without using <code>QPushbutton</code> or <code>addWidget</code> methods?. Hope you can help me  </p>
  
  <h2>------ EDIT ------</h2>
  
  <p>Based on @three_pineapples comment, Ihave tried to add this class to my code:</p>
  
  <pre><code>class MyToolbar(NavigationToolbar2):
    def __init__(self):
      NavigationToolbar2.__init__(self)
      self.iconDir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
          "..", "images", "icons", "")
  
      self.a = self.addAction(QIcon(iconDir + "BYE2.ico"),
          "Bye", self.bye)
      self.a.setToolTip("GoodBye")
  
    def bye(self):
      print "See you next time")
  </code></pre>
  
  <p>And I instantiated doing:</p>
  
  <p><code>self.navigation_toolbar = MyToolbar()</code>,  instead of: </p>
  
  <p><code>self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)</code>  </p>
  
  <p>But, I am getting this error: </p>
  
  <p><code>TypeError: __init__() takes at least 3 arguments (1 given)</code></p>
  
  <p>I´ve tried adding <code>*args</code> and <code>kwargs</code>, but I do not know what i am missing here. </p>
  
  <p>Is this the way to add a button to the matplotlib´s toolbar? Hope you can help me. </p>