from qgis.core import QgsApplication QgsApplication.setPrefixPath("/usr", True) # set the path to the QGIS installation app = QgsApplication([], True) app.initQgis() icon_path = app.iconPath("mActionSaveProject.png") print(icon_path) # '/usr/share/qgis/icons/mActionSaveProject.png' app.exitQgis()
from qgis.core import QgsApplication QgsApplication.setPrefixPath("/usr", True) # set the path to the QGIS installation app = QgsApplication([], True) app.initQgis() icon_file = "my_custom_icon.png" icon_path = app.iconPath(icon_file) if icon_path: print("Using custom icon: ", icon_path) else: print("Error: icon file not found") app.exitQgis()In this example, the iconPath method is used to retrieve the path of a custom icon named "my_custom_icon.png" and check if the file exists. Both examples use the QgsApplication module from the QGIS library to set up and initialize the QGIS application before using the iconPath() method.