from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtWidgets import QAction # Create QAction my_action = QAction(QIcon('icon.png'), 'My Action', parent=None) my_action.setToolTip('Click to perform action') # Connect to function def my_function(): print('Action performed') my_action.triggered.connect(my_function)
from qgis.PyQt.QtCore import Qt from qgis.utils import iface # Get QGIS toolbar and add QAction toolbar = iface.addToolBar('My Toolbar') toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # optional toolbar.addAction(my_action)In these examples, the package library being used is the PyQt module from the QGIS package. The QAction is used to create a graphical user interface widget that can be clicked on by the user to perform an action, such as printing text to the console or executing a function.