QToolButton
Starting from QGIS 2.0 there is iface.addToolBarWidget
which lets you add a QToolButton which allows fine grained control over dropdown behavior and appearance.
self.action1 = QAction(QIcon(":/action1.png"), u"Action 1", self.iface.mainWindow())
self.action2 = QAction(QIcon(":/action2.png"), u"Action 2", self.iface.mainWindow())
self.action3 = QAction(QIcon(":/action3.png"), u"Action 3", self.iface.mainWindow())
self.popupMenu = QMenu( self.iface.mainWindow() )
self.popupMenu.addAction( self.action1 )
self.popupMenu.addAction( self.action2 )
self.popupMenu.addAction( self.action3 )
self.action1.triggered.connect( self.someMethod1 )
self.action2.triggered.connect( self.someMethod2 )
self.action3.triggered.connect( self.someMethod3 )
self.toolButton = QToolButton()
self.toolButton.setMenu( self.popupMenu )
self.toolButton.setDefaultAction( self.action1 )
self.toolButton.setPopupMode( QToolButton.InstantPopup )
self.iface.addToolBarWidget( self.toolButton )
QGIS <= 1.8
Up to QGIS 1.8, you could not do quite the same thing, because you could only add QActions to the QToolBar, but no QToolButtons ( which would let you set the PopupMode manually)
But you can get almost the same result if you assign a QMenu to your action, and to this menu you can add other actions. I did not find a possibility to change the PopupMode for this to anything else than MenuButtonPopup.
self.action1 = QAction(QIcon(":/action1.png"), u"Action 1", self.iface.mainWindow())
self.action2 = QAction(QIcon(":/action2.png"), u"Action 2", self.iface.mainWindow())
self.action3 = QAction(QIcon(":/action3.png"), u"Action 3", self.iface.mainWindow())
self.popupMenu = QMenu( self.iface.mainWindow() )
self.popupMenu.addAction( self.action2 )
self.popupMenu.addAction( self.action3 )
self.action1.triggered.connect( self.someMethod1 )
self.action2.triggered.connect( self.someMethod2 )
self.action3.triggered.connect( self.someMethod3 )
self.action1.setMenu( self.popupMenu )
self.iface.addToolBarIcon(self.action1)