如何在QGIS工具栏上添加按钮或创建自己的工具栏?


11

我想创建一个按钮并将其添加到QGIS工具栏,或者创建我自己的工具栏并在此处添加按钮。

用户单击按钮时应启动一个插件。

Answers:


11

您可以将图标添加到工具栏或菜单。有关更多信息,请参见pyqgis Cookbook http://www.qgis.org/pyqgis-cookbook/plugins.html

def initGui(self):
    # create action that will start plugin configuration
    self.action = QAction(QIcon(":/plugins/testplug/icon.png"), "Test plugin", self.iface.mainWindow())
    self.action.setWhatsThis("Configuration for test plugin")
    self.action.setStatusTip("This is status tip")
    QObject.connect(self.action, SIGNAL("triggered()"), self.run)

    # add toolbar button and menu item
    self.iface.addToolBarIcon(self.action)
    self.iface.addPluginToMenu("&Test plugins", self.action)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.