I have set some actions for my plugin and now I want to group all of them in a dropdown menu as one of the image, which is from another plugin. I've been struggling but I can't find a way to do it like that.
I have tried this:
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
icon_path = ':/plugins/udt_plugin/icon.png'
self.action1 = QAction(QIcon(icon_path), u"Action 1", self.iface.mainWindow())
self.action2 = QAction(QIcon(icon_path), u"Action 2", self.iface.mainWindow())
self.action3 = QAction(QIcon(icon_path), 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.toolButton = QToolButton()
self.toolButton.setMenu(self.popupMenu)
self.toolButton.setDefaultAction(self.action1)
self.toolButton.setPopupMode(QToolButton.InstantPopup)
self.iface.addToolBarWidget(self.toolButton)
But it creates a more simple dropdown menu like below, which is not exactly what I want. I'm using QGIS 3.10.