2

I am creating a QGIS plugin that will use some general tools available in QGIS like "identify features" and a plugin like a "digitizing tool". Is it possible for example to link a button of my plugin to identify features tool, so when the user click on the button, will call the identify features tool?

I am using QGIS 3.4

2 Answers 2

3

Yes it is possible and you need to execute a desired QAction. For "identify feature tool", you can trigger "mActionIdentify" action. A list of most of the available actions can be found by going to "Settings->Interface Customization". Here you will find reference to the most of the possible customization e.g. Actions, buttons, toolbars, docking widgets and etc.

Using Python, you can call following command to get the list of all the possible actions in QGIS.

[action.text() for action in iface.mainWindow().findChildren(QAction)]

Replace QAction with any other widget type e.g. QDockWidget, if you require so.

Side Note: If you just need to do actions customization, then you can use "Qgist Toolbar Generator" plugin. Here you can create customized toolbars and share with other users. A Screenshot of this plugin with possible values is given below. enter image description here

A new toolbar like the following will be added to QGIS. You can use them as regular toolbar and share with others.

enter image description here

3

Yes, it is possible! The following is a very short and effective example (that I'll explain below):

toolbar = iface.addToolBar("My ToolBar")

# Add QGIS action from iface
toolbar.addAction(iface.actionIdentify())

# Add 'Digitizing tools' plugin action (e.g., Merge)
dt = qgis.utils.plugins['DigitizingTools']
toolbar.addAction(dt.merger.act)

Which gives you this right away (left: QGIS tool, right: tool fromDigitizing tools plugin):

enter image description here

Using QGIS actions

It is true that you can search for actions giving their object names (e.g., mActionIdentify). However, the QGIS API is friendly enough to give you access to commonly used actions directly (i.e., no need to find them for yourself). It is done via the iface object (see QgisInterface).

For instance, for accessing the QGIS Identify action, you can use iface.actionIdentify() See the docs.

Using actions from another plugin

This case depends on how well or flexible is the plugin written. For instance, the Digitizing tools plugin is very friendly for you to reuse its tools/actions. You can have a look at its tools in this code fragment.

Continuing with such example, if you're interested in the Merge tool from the 'Digitizing tools' plugin, then you can use the merger object. To get the action related to that tool, you use merger.act (which is very specific for the Digitizing tools plugin). Other plugins may need other ways to access their actions, or may even not allow you to reuse their actions at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.