currently i want to add a qgis toolbar icon, which needs to be populated on the qgis window after certain process using custom class by overriding the current qgisinterface. But while running the code i got no issue on the code but the toolbar icon is not populating. Anyone can look at the code for related bugs.
class CustomMenuPlugin:
def __init__(self, iface):
self.iface = iface
def initGui(self):
self.toolbar = self.iface.addToolBar("CustomMenu")
self.add_custom_menu()
def add_custom_menu(self):
custom_menu = QMenu("Custom Menu", self.iface.mainWindow())
action1 = QAction("Action 1", self.iface.mainWindow())
action1.triggered.connect(self.custom_action_triggered)
custom_menu.addAction(action1)
action2 = QAction("Action 2", self.iface.mainWindow())
action2.triggered.connect(self.custom_action_triggered)
custom_menu.addAction(action2)
# You can add more actions as needed
self.custom_menu_button = QAction("Custom Menu", self.iface.mainWindow())
self.custom_menu_button.setMenu(custom_menu)
self.toolbar.addAction(self.custom_menu_button)
def unload(self):
self.iface.removeToolBarIcon(self.toolbar, self.custom_menu_button)
def custom_action_triggered(self):
# Implement the logic for your custom actions here
pass
custom_menu_plugin = CustomMenuPlugin(self.obj_iface)
initGuifunction never gets called.self.obj_ifaceis aQgisInterfaceobject then yourunload()function will raise errorTypeError: QgisInterface.removeToolBarIcon(): argument 1 has unexpected type 'QToolBar'